-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheck_dsl.py
executable file
·55 lines (39 loc) · 1.23 KB
/
check_dsl.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
"""
check_dsl.py
Check my DSL modem and see if it's still online.
If it goes down, issue a reboot on the RPC.
Note that this must be run as root. Ping.py requires root to generate
raw sockets.
J. Adams <[email protected]>
"""
import syslog
import sys
from rpc3Control import *
from ping import *
UPLINK="75.101.56.1"
RPC=None
RPCUSER=None
RPCPASS=None
OUTLET=6
TIMEOUT=3
CNT=3
(RPC, RPCUSER, RPCPASS, WHITELIST) = load_credentials("/retina/check_dsl/.credentials")
# syslog.syslog(syslog.LOG_NOTICE, 'Checking network.')
if __name__ == '__main__':
count = 1
while (count < (CNT+1)):
syslog.syslog(syslog.LOG_NOTICE, "Checking DSL... Try #%d" % count)
result = do_one(UPLINK, TIMEOUT)
if result != None:
# we're good.
syslog.syslog(syslog.LOG_NOTICE, "PING OK. Try #%d" % count)
sys.exit(0)
syslog.syslog(syslog.LOG_NOTICE, "PING FAILED. Try #%d" % count)
count += 1
# fuck, the network is down!
syslog.syslog(syslog.LOG_NOTICE, 'PING FAILED. Rebooting DSL Modem')
r = rpc3Control(RPC, RPCUSER, RPCPASS, False)
r.outlet(OUTLET, 'reboot')
syslog.syslog(syslog.LOG_NOTICE, 'Reboot complete.')
sys.exit(1)