forked from finish06/pyunifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unifi-save-radius
executable file
·46 lines (34 loc) · 1.76 KB
/
unifi-save-radius
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
40
41
42
43
44
45
46
#!/usr/bin/env python
import argparse
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")')
parser.add_argument('-V', '--no-ssl-verify', default=False, action='store_true', help='Don\'t verify ssl certificates')
parser.add_argument('-C', '--certificate', default='', help='verify with ssl certificate pem file')
parser.add_argument('-f', '--file', default='radius-unifi.csv', help='the filename of write statistics')
args = parser.parse_args()
ssl_verify = (not args.no_ssl_verify)
if ssl_verify and len(args.certificate) > 0:
ssl_verify = args.certificate
c = Controller(args.controller, args.username, args.password, args.port, args.version, args.siteid, ssl_verify=ssl_verify)
users = c.get_radius_users()
users.sort(key=lambda x: x['name'])
#open file
fo = open(args.file, "wb")
FORMAT_CSV = '%s, %s, %s, %s\n'
fo.write(FORMAT_CSV % ('USERNAME', 'PASSWORD', 'ID', 'SITE ID'))
for user in users:
name = user["name"]
password = user["x_password"]
id = user["_id"]
site_id = user["site_id"]
fo.write(FORMAT_CSV % (name, password, id, site_id))
# Close file
fo.close()
# Print result of file
print(open(args.file,"rb").read())