From c6457842cee4cc15276a1c685471111c1bab9bdb Mon Sep 17 00:00:00 2001 From: Sean Corrigan Date: Mon, 21 Dec 2020 13:10:40 -0500 Subject: [PATCH] I think this is it for the code. --- main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..ad9fdcc --- /dev/null +++ b/main.py @@ -0,0 +1,46 @@ +## Sean Corrigan 2020 + +import os +from time import sleep + +# All of these IPs need to return failed pings in +# order to shutdown | Make sure not to use the curren devices IP! +hosts = ['192.168.0.1', '192.168.0.2'] + +def ping(hostname = '1.1.1.1'): + # ping our host + response = os.system("ping -c 1 " + hostname) + # and then check the response... + if response == 0: + return True + else: + return False + +def main(shutdownbit = False): + hostpings = {} + for host in hosts: + hostpings[host] = ping(host) + bit = False ## Shows that all hosts are down + for host in hostpings: + if hostpings[host]: # if any hosts respond to ping + bit = 1 # set bit as OK + + if not bit: # IF BIT IS STILL FALSE + if shutdownbit: + print("\n\n\nCONNECTIVITY LOST, SHUTTING DOWN\n\n") + else: + print("\n\nCONNECTIVITY LOST, RUNNING SANITY CHECK") + sleep(5) + main(True) + + + +if __name__ == "__main__": + while True: + # try: + main() + # except: + # pass + for i in range(1,10): + print(i) + sleep(1) \ No newline at end of file