Skip to content

Instantly share code, notes, and snippets.

@whoizit
Last active May 4, 2019 04:03
Show Gist options
  • Save whoizit/5418838ad7660bb8260233a773a85c88 to your computer and use it in GitHub Desktop.
Save whoizit/5418838ad7660bb8260233a773a85c88 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.7
# requirements:
# python3.7
# pip3.7 install shell-scripting
# fping
#
# instruction:
# git clone https://github.com/yggdrasil-network/public-peers
# cd public-peers
# path/to/yggdrasil-ping-public-peers <region> | sort -rn
from shell_scripting import shell, shell_list
from sys import argv
from glob import glob
fileList = glob(argv[1] + '/*.md')
lastList = []
for x in fileList:
output = shell_list(f'grep -hR tcp:// {x}')
for y in output:
if any(v6 in '[]' for v6 in y):
v6_1 = y.find('[') + 1
v6_2 = y.find(']')
v6_3 = y[v6_2:].find('`') + v6_2
lastList.append([x.split('.md')[0], y[v6_1:v6_2], y[v6_2 + 2:v6_3]])
elif 'tcp://' in y:
v4_1 = y.find('tcp://') + 6
v4_2 = y[v4_1:].find(':') + v4_1
v4_3 = y[v4_2:].find('`') + v4_2
lastList.append([x.split('.md')[0], y[v4_1:v4_2], y[v4_2 + 1:v4_3]])
for x, y, z in lastList:
try:
ping_out = shell('fping -c1 -q {}'.format(y)).stderr.split('=')[2].strip()
ping = float(ping_out.split('/')[0])
if ':' in y:
print('{:<7}{:<24}"[{}]:{}"'.format(ping, x, y, z))
else:
print('{:<7}{:<24}{}:{}'.format(ping, x, y, z))
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment