41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
import requests
|
|
import json
|
|
import urllib3
|
|
urllib3.disable_warnings()
|
|
|
|
s = requests.Session()
|
|
login_url = "https://140.44.44.1/api/auth/login"
|
|
login_payload = {"username": "Snarf", "password": "Katzir476!!!"}
|
|
|
|
try:
|
|
r = s.post(login_url, json=login_payload, verify=False, timeout=5)
|
|
print("UniFi login:", r.status_code)
|
|
|
|
# Query clients
|
|
r = s.get("https://140.44.44.1/proxy/network/api/s/default/stat/sta", verify=False, timeout=5)
|
|
if r.status_code == 200:
|
|
clients = r.json().get("data", [])
|
|
print(f"Total active clients: {len(clients)}")
|
|
target_mac = "bc:24:11:67:16:cd"
|
|
found = False
|
|
for c in clients:
|
|
if c.get("mac") == target_mac:
|
|
print("FOUND CLIENT:", json.dumps(c, indent=2))
|
|
found = True
|
|
break
|
|
if not found:
|
|
print(f"Client {target_mac} not active. Checking configured/known clients...")
|
|
r2 = s.get("https://140.44.44.1/proxy/network/api/s/default/rest/user", verify=False, timeout=5)
|
|
if r2.status_code == 200:
|
|
known = r2.json().get("data", [])
|
|
for k in known:
|
|
if k.get("mac") == target_mac:
|
|
print("FOUND IN KNOWN USERS:", json.dumps(k, indent=2))
|
|
found = True
|
|
break
|
|
if not found:
|
|
print(f"MAC {target_mac} not found in UniFi.")
|
|
except Exception as e:
|
|
print("UniFi error:", e)
|
|
|