forked from r0n22/Internet_Monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinternet_checkPIresetRouter.py
More file actions
37 lines (33 loc) · 982 Bytes
/
Copy pathinternet_checkPIresetRouter.py
File metadata and controls
37 lines (33 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
import socket
import RPi.GPIO as GPIO
import time
import syslog
PIN = 12
def is_connected(REMOTE_SERVER):
try:
# see if we can resolve the host name -- tells us if there is a DNS listening
host = socket.gethostbyname(REMOTE_SERVER)
# connect to the host -- tells us if the host is actually reachable
s = socket.create_connection((host, 80), 2)
# syslog.syslog('Successful Test')
return True
except:
pass
return False
def ResetRouter():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN, GPIO.OUT)
GPIO.output(PIN,1) # turn on pin
syslog.syslog('Modem Reset')
time.sleep( 5 ) # sleep for 5
GPIO.output(PIN,0) # turn off pin
GPIO.cleanup() # cleanup
def main():
if not (is_connected("www.google.ca") and is_connected("www.cnn.com")):
ResetRouter()
else:
syslog.syslog('Internet Up')
if __name__ == "__main__":
main()