I have a Python script that runs by ping to determine the internet speed every 30 seconds, to see if a user can receive a call over the internet, ping is often not enough to know this so I want more information like download speed and network upload speed and so on.
How can this happen in Python without having a significant impact on the Internet so that it does not cause a slow internet
`
def check_ping(host):
"""
Returns formated min / avg / max / mdev if there is a vaild host
Return None if host is not vaild
"""
# Option for the number of packets as a function of
param = '-n' if platform.system().lower() == 'windows' else '-c'
# Building the command. Ex: "ping -c 1 $host"
command = ['ping', param, '3', host]
# ask system to make ping and return output
ping = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, error = ping.communicate()
matcher = re.compile(
"(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)")
# rtt min/avg/max/mdev =
ping_list = r"Minimum = (\d+)ms, Maximum = (\d+)ms, Average = (\d+)ms"
try:
if(not error):
if(platform.system().lower() == 'windows'):
response = re.findall(ping_list, out.decode())[0]
return response
else:
response = matcher.search(out.decode()).group().split('/')
return response
except Exception as e:
logging.error(e)
return None
`