Created
December 10, 2020 02:36
-
-
Save doorknob60/28017d1fabc0b339cdde17d60e3fc012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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