Skip to content

Instantly share code, notes, and snippets.

@rivmar
Created March 23, 2018 09:17
Show Gist options
  • Save rivmar/f218d27da8ec32c34362a5e687df400c to your computer and use it in GitHub Desktop.
Save rivmar/f218d27da8ec32c34362a5e687df400c 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