Skip to content

Instantly share code, notes, and snippets.

@aksiksi
Last active March 30, 2016 09:31
Show Gist options
  • Save aksiksi/3b72071630b7c980a4096b55cd4d6b81 to your computer and use it in GitHub Desktop.
Save aksiksi/3b72071630b7c980a4096b55cd4d6b81 to your computer and use it in GitHub Desktop.
Simple script to test DigitalOcean's datacenters speed
#!/usr/bin/env python
import subprocess
class SpeedTest(object):
datacenters = [
{
'name': 'NYC1',
'host': 'speedtest-nyc1.digitalocean.com',
'ip': '198.211.112.36',
'location': 'New York, USA',
},
{
'name': 'NYC2',
'host': 'speedtest-nyc2.digitalocean.com',
'ip': '162.243.123.82',
'location': 'New York, USA',
},
{
'name': 'NYC3',
'host': 'speedtest-nyc3.digitalocean.com',
'ip': '104.131.63.93',
'location': 'New York, USA',
},
{
'name': 'AMS1',
'host': 'speedtest-ams1.digitalocean.com',
'ip': '146.185.176.179',
'location': 'Amsterdam, Netherlands',
},
{
'name': 'AMS2',
'host': 'speedtest-ams2.digitalocean.com',
'ip': '95.85.7.154',
'location': 'Amsterdam, Netherlands',
},
{
'name': 'AMS3',
'host': 'speedtest-ams3.digitalocean.com',
'ip': '178.62.255.144',
'location': 'Amsterdam, Netherlands',
},
{
'name': 'SFO1',
'host': 'speedtest-sfo1.digitalocean.com',
'ip': '162.243.146.51',
'location': 'San Francisco, USA',
},
{
'name': 'SGP1',
'host': 'speedtest-sgp1.digitalocean.com',
'ip': '128.199.236.18',
'location': 'Singapore',
},
{
'name': 'LON1',
'host': 'speedtest-lon1.digitalocean.com',
'ip': '46.101.51.122',
'location': 'London, UK',
},
{
'name': 'FRA1',
'host': 'speedtest-fra1.digitalocean.com',
'ip': '46.101.189.30',
'location': 'Frankfurt, Germany',
}
]
def ping(self, host, requests=1):
try:
return subprocess.check_output([
'ping',
'-c{:d}'.format(requests),
host,
])
except subprocess.CalledProcessError as exception:
print('The host {} is not reachable'.format('host'))
def run(self, requests):
for datacenter in self.datacenters:
response = str(self.ping(datacenter['host'], requests)) # Convert from bytes to str
print('Datacenter: {}'.format(datacenter['name']))
print('Host: {} ({})'.format(datacenter['host'], datacenter['ip']))
print('Location: {}'.format(datacenter['location']))
print('Ping statistics for {:d} requests:'.format(requests))
print(' ' + '\n '.join(response.strip().split('\n')[-2:]), '\n')
if __name__ == '__main__':
test = SpeedTest()
test.run(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment