-
Notifications
You must be signed in to change notification settings - Fork 0
/
zerotier-status.py
71 lines (55 loc) · 2.08 KB
/
zerotier-status.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
import requests
from colorama import init
init(autoreset=True)
zerotier_ID=""
API_Tokens=""
def resultFormat(data):
nodeId = "{:<10.10}".format(data['nodeId'])+"\t"
name = format(data['name'])
if data['online'] == True :
online = "{:<10.10}".format("online") +"\t"
else:
online = "{:<10.10}".format("offline") +"\t"
clientVersion = "{:<13.13}".format(data['clientVersion']) +"\t"
ipv4=[]
ipv6=[]
for ip in data['config']['ipAssignments']:
if ( ip.find(".",0,len(ip)) != -1 ):
ipv4.append(ip)
elif (ip.find(":",0,len(ip)) != -1 ):
ipv6.append(ip)
ipv4.extend(ipv6)
ipAssignments=""
for x in range(len(ipv4)):
ipAssignments= ipAssignments +ipv4[x]
if(x<len(ipv4)-1):
ipAssignments = ipAssignments +" / "
if data['physicalAddress']== None :
physicalAddress = "{:<20.20}".format("")
elif len(data['physicalAddress']) > 15:
physicalAddress = "{:<15.15}".format(data['physicalAddress'])
physicalAddress = physicalAddress + "....."
else:
physicalAddress = "{:<20.20}".format(data['physicalAddress'])
physicalAddress = physicalAddress +"\t"
return nodeId + '{name:<{len}}'.format(name=name,len=20-len(name.encode('GBK'))+len(name)) + "\t"+ online + clientVersion + physicalAddress + ipAssignments
headers={"Authorization": "bearer "+API_Tokens}
curls="https://my.zerotier.com/api/network/"+zerotier_ID+"/member"
r = requests.get(curls, headers=headers)
if r.status_code != 200 :
print("zerotierID或API_Tokens设置,请重新设置!!")
data=r.json()
title = '\033[1;32m'
title = title + "No "
title = title + "{:<10.10}".format('nodeId')+"\t"
title = title + '{name:<{len}}'.format(name="name",len=20-len("name".encode('GBK'))+len("name")) + '\t'
title = title + "{:<10.10}".format("online") +"\t"
title = title + "{:<13.13}".format('clientVersion') +"\t"
title = title + "{:<20.20}".format('physicalAddress') + "\t"
title = title + "ipAssignments"
title = title + '\033[0m'
print(title)
for x in range(len(data)):
outstr = resultFormat(data[x])
print("{:0>2d}".format(x+1)+" "+outstr)