53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Simple UniFi test - generates report"""
|
|
|
|
import requests
|
|
import urllib3
|
|
from datetime import datetime
|
|
|
|
urllib3.disable_warnings()
|
|
|
|
URL = "https://192.168.0.39:8443"
|
|
USER = "corey"
|
|
PASS = "is41945549"
|
|
|
|
# Login
|
|
login = requests.post(f"{URL}/api/auth/login", json={"username": USER, "password": PASS}, verify=False, timeout=10)
|
|
login.raise_for_status()
|
|
cookies = login.cookies
|
|
|
|
# Get clients
|
|
clients = requests.get(f"{URL}/proxy/network/api/s/default/stat/sta", cookies=cookies, verify=False, timeout=10).json().get('data', [])
|
|
|
|
# Get devices
|
|
devices = requests.get(f"{URL}/proxy/network/api/s/default/stat/device", cookies=cookies, verify=False, timeout=10).json().get('data', [])
|
|
|
|
# Count by type
|
|
wired = sum(1 for c in clients if c.get('is_wired', False))
|
|
wireless = len(clients) - wired
|
|
|
|
# Generate simple report
|
|
report = f"""# UniFi Network Report - {datetime.now().strftime('%Y-%m-%d %H:%M')}
|
|
|
|
## Connected Clients: {len(clients)}
|
|
- Wireless: {wireless}
|
|
- Wired: {wired}
|
|
|
|
## UniFi Devices: {len(devices)}
|
|
|
|
### Sample Wireless Clients:
|
|
"""
|
|
|
|
for idx, c in enumerate([x for x in clients if not x.get('is_wired', False)][:5], 1):
|
|
name = c.get('name', c.get('hostname', 'Unknown'))
|
|
ip = c.get('ip', 'N/A')
|
|
report += f"{idx}. {name} - {ip}\n"
|
|
|
|
report += f"\n### UniFi Devices:\n"
|
|
for idx, d in enumerate(devices[:5], 1):
|
|
name = d.get('name', d.get('mac', 'Unknown'))
|
|
model = d.get('model', 'Unknown')
|
|
report += f"{idx}. {name} ({model})\n"
|
|
|
|
print(report)
|