跨平台的丢包率检测

This commit is contained in:
ubuntu 2018-08-28 17:25:25 +08:00
parent 35f363edf8
commit 46def9acb2

@ -126,14 +126,14 @@ def get_network(ip_version):
lostRate = {}
def _ping_thread(host, mark):
output = os.popen('ping %s -t &' % host)
output = os.popen('ping -O %s &' % host if 'linux' in sys.platform else 'ping %s -t &' % host)
lostCount = 0
allCount = 0
startTime = time.time()
output.readline()
output.readline()
while True:
if 'TTL' not in output.readline():
if 'TTL' not in output.readline().upper():
lostCount += 1
allCount += 1
lostRate[mark] = "%.4f" % (float(lostCount) / allCount)