forked from finish06/pyunifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unifi-log-roaming
executable file
·39 lines (31 loc) · 1.48 KB
/
unifi-log-roaming
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
from __future__ import print_function
import argparse
import time
from pyunifi.controller import Controller
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--controller', default='unifi', help='the controller address (default "unifi")')
parser.add_argument('-u', '--username', default='admin', help='the controller username (default "admin")')
parser.add_argument('-p', '--password', default='', help='the controller password')
parser.add_argument('-b', '--port', default='8443', help='the controller port (default "8443")')
parser.add_argument('-v', '--version', default='v5', help='the controller base version (default "v5")')
parser.add_argument('-s', '--siteid', default='default', help='the site ID, UniFi >=3.x only (default "default")')
args = parser.parse_args()
c = Controller(args.controller, args.username, args.password, args.port, args.version, args.siteid)
aps = c.get_aps()
ap_names = dict([(ap['mac'], ap.get('name')) for ap in aps])
client_aps = {}
while True:
clients = c.get_clients()
for client in clients:
ap = ap_names[client['ap_mac']]
mac = client['mac']
name = client['hostname'] or client['ip'] or client['mac']
channel = client['channel']
rssi = client['rssi']
key = '%s/%d' % (ap, channel)
if mac in client_aps:
if client_aps[mac] != key:
print('%s roamed %s -> %s' % (name, client_aps[mac], key))
client_aps[mac] = key
time.sleep(10)