-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathburginfo.py
executable file
·40 lines (32 loc) · 1.06 KB
/
burginfo.py
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
#!/usr/bin/env python3
import datetime
import http.client
import json
import nodesTk
import socket
import urllib
api_version = 1
if __name__ == "__main__":
with open("config.json", "r") as f:
config = json.load(f)
result = dict()
try:
net = nodesTk.generate_from_urls(config["nodes_json"], config["graph_json"])
except (TypeError, socket.gaierror, urllib.error.URLError, http.client.IncompleteRead):
net = None
if net:
try:
net.vpn_only_nodes = set(config["vpn_only_nodes"])
except KeyError:
pass
routers = set()
for mac in config["known_hosts"]:
routers |= net.get_mesh_of_node(mac)
result["version"] = api_version
result["updated"] = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
result["nodes"] = len(routers)
result["clients"] = 0
for mac in routers:
result["clients"] += net.get_node(mac).client_count
with open(config["output"], "w") as f:
json.dump(result, f)