Created
December 19, 2021 13:55
-
-
Save sdsdkkk/b28a96f83c4c7c8a3b9075b5d8231e93 to your computer and use it in GitHub Desktop.
ISP uptime checker process script
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
from ping3 import ping | |
from datetime import datetime | |
from time import sleep | |
import sys | |
TARGET_HOSTS = [ | |
'google.com', | |
'facebook.com', | |
'firstmedia.com' | |
] | |
DELAY = 60 | |
isp_up_stat = True | |
print('Initiating ISP uptime check service at {}'.format(datetime.now())) | |
while True: | |
try: | |
curr_stat = isp_up_stat | |
for host in TARGET_HOSTS: | |
curr_stat = ping(host) | |
if curr_stat is not False: | |
curr_stat = True | |
break | |
if isp_up_stat == curr_stat: | |
sleep(DELAY) | |
continue | |
isp_up_stat = curr_stat | |
curr_time = datetime.now() | |
if curr_stat == False: | |
print('Down at {}'.format(curr_time)) | |
else: | |
print('Up at {}'.format(curr_time)) | |
sleep(DELAY) | |
except Exception as e: | |
print(e) | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment