Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DigitalOcean region latency check
#!/usr/bin/env python3
import subprocess
import re
def gen_hosts():
Current regions list on
regions = [
for region in regions:
yield "{}:http:speedtest-{}".format(region, region)
def get_hosts():
result = None
for line in gen_hosts():
site, schema, hostname = line.split(":")
yield site, hostname.replace("/", "").strip()
def do_ping(hostname, count=10):
process = subprocess.Popen(["ping", "-c", str(count), hostname], stdout=subprocess.PIPE)
return filter_output(
def filter_output(output):
result = re.match(b".+rtt .+ = [0-9.]+/([0-9.]+)", output, re.M | re.S)
if result != None:
return result.groups()[0].decode("ascii")
return None
for site, hostname in get_hosts():
time = do_ping(hostname)
if time != None:
print(site, hostname, time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment