perform ICMP pings on posix systems
This commit is contained in:
parent
cbb249b96d
commit
ec41eb5e1d
|
@ -316,19 +316,24 @@ def getBestServer(servers):
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
for server in servers:
|
for server in servers:
|
||||||
cum = 0
|
|
||||||
url = os.path.dirname(server['url'])
|
url = os.path.dirname(server['url'])
|
||||||
for i in range(0, 3):
|
if os.name == 'posix':
|
||||||
uh = urlopen('%s/latency.txt' % url)
|
cmd = 'ping -c 3 ' + url.split('/')[2] + ' | tail -n 1'
|
||||||
start = time.time()
|
pingoutput = os.popen(cmd).read()
|
||||||
text = uh.read().strip()
|
avg = pingoutput.split('/')[4]
|
||||||
total = time.time() - start
|
else:
|
||||||
if int(uh.code) == 200 and text == 'test=test'.encode():
|
cum = 0
|
||||||
cum += total
|
for i in range(0, 3):
|
||||||
else:
|
uh = urlopen('%s/latency.txt' % url)
|
||||||
cum += 3600
|
start = time.time()
|
||||||
uh.close()
|
text = uh.read().strip()
|
||||||
avg = round((cum / 3) * 1000000, 3)
|
total = time.time() - start
|
||||||
|
if int(uh.code) == 200 and text == 'test=test'.encode():
|
||||||
|
cum += total
|
||||||
|
else:
|
||||||
|
cum += 3600
|
||||||
|
uh.close()
|
||||||
|
avg = round((cum / 3) * 1000000, 3)
|
||||||
results[avg] = server
|
results[avg] = server
|
||||||
|
|
||||||
fastest = sorted(results.keys())[0]
|
fastest = sorted(results.keys())[0]
|
||||||
|
|
Loading…
Reference in New Issue