46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
## 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) |