Skip to content

Instantly share code, notes, and snippets.

@doorknob60
Created December 10, 2020 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doorknob60/28017d1fabc0b339cdde17d60e3fc012 to your computer and use it in GitHub Desktop.
Save doorknob60/28017d1fabc0b339cdde17d60e3fc012 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import csv
import datetime
import signal
import sys
import time
from pythonping import ping
PINGURL1 = "sea15s07-in-f78.1e100.net" # A Google server
PINGURL2 = "oldschool31.runescape.com"
TIMEOUT = 10
def exit_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, exit_handler)
while True:
timestamp = str(datetime.datetime.today().replace(microsecond=0))
p1 = ping(PINGURL1, count=1)
p2 = ping(PINGURL2, count=1)
time1 = round(p1.rtt_avg * 1000, 2)
time2 = round(p2.rtt_avg * 1000, 2)
with open('ping.csv', 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([timestamp, time1, time2])
time.sleep(TIMEOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment