Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Wayeet/4aba3924134f4583f670fb7ce8082097 to your computer and use it in GitHub Desktop.
Save Wayeet/4aba3924134f4583f670fb7ce8082097 to your computer and use it in GitHub Desktop.
[Python] Get server ping time
import re
import subprocess
host = 'google.com'
try:
output = subprocess.check_output(['ping', '-c', '4', '-q', host])
output = output.decode('utf8')
statistic = re.search(r'(\d+\.\d+/){3}\d+\.\d+', output).group(0)
avg_time = re.findall(r'\d+\.\d+', statistic)[1]
response_time = float(avg_time)
except subprocess.CalledProcessError:
response_time = 99999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment