-
Notifications
You must be signed in to change notification settings - Fork 0
/
cjdnsPING.py
29 lines (28 loc) · 939 Bytes
/
cjdnsPING.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
import requests, json
import subprocess
import shlex
data = requests.get('https://raw.githubusercontent.com/tomeshnet/node-list/master/nodeList.json').json()
result = {}
for value in data:
if "IPV6Address" in value:
node = {}
command_line = "ping6 -c 5 " + value["IPV6Address"]
args = shlex.split(command_line)
ping = subprocess.Popen(args,stdout=subprocess.PIPE)
ping.wait()
output = ping.stdout.read()
lines = output.split("\n")
for line in lines:
if line.find("packets transmitted") > -1:
words = line.split()
node.update({'loss' : words[5]})
node.update({'status' : "dead" })
if line.find("rtt") > -1:
words = line.split()
pingData = words[3].split("/")
node.update({'pingMin' : pingData[0]})
node.update({'pingAvg' : pingData[1]})
node.update({'pingMax' : pingData[2]})
node.update({'status' : "ok" })
result.update({value["IPV6Address"] : node})
print json.dumps(result)