Mercurial > ~darius > hgwebdir.cgi > adslstats
comparison speedcheck.py @ 35:815e6b61d76e
Decode to string to work with Python 3.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 14 Nov 2020 15:05:07 +1030 |
parents | 1af6865189ce |
children | 1a87c79cf103 |
comparison
equal
deleted
inserted
replaced
34:b79c03810bbe | 35:815e6b61d76e |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 import configparser | 3 import configparser |
4 import optparse | 4 import optparse |
5 import os | 5 import os |
6 import re | 6 import re |
74 return float(speed) * 8.0 / 1024.0 # convert to kbit/sec | 74 return float(speed) * 8.0 / 1024.0 # convert to kbit/sec |
75 | 75 |
76 def testping(host): | 76 def testping(host): |
77 p = subprocess.Popen(['ping', '-c', '5', '-t', '8', '-q', host], stdout = subprocess.PIPE) | 77 p = subprocess.Popen(['ping', '-c', '5', '-t', '8', '-q', host], stdout = subprocess.PIPE) |
78 stdout, stderr = p.communicate() | 78 stdout, stderr = p.communicate() |
79 l = stdout.split('\n') | 79 l = stdout.decode('ascii', 'ignore').split('\n') |
80 if len(l) != 6: | 80 if len(l) != 6: |
81 print('Unable to parse ping line:', l) | 81 print('Unable to parse ping line:', l) |
82 xx, xx, xx, plossline, latline, xx = l | 82 xx, xx, xx, plossline, latline, xx = l |
83 ploss = float(re.match('.* received, ([0-9.]+)% packet loss', plossline).groups()[0]) | 83 ploss = float(re.match('.* received, ([0-9.]+)% packet loss', plossline).groups()[0]) |
84 latency = float(re.match('.*stddev = [0-9.]+/([0-9.]+)/.* ms', latline).groups()[0]) | 84 latency = float(re.match('.*stddev = [0-9.]+/([0-9.]+)/.* ms', latline).groups()[0]) |