-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_net.py
More file actions
executable file
·36 lines (31 loc) · 1002 Bytes
/
check_net.py
File metadata and controls
executable file
·36 lines (31 loc) · 1002 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
#!/usr/bin/env python
import os
import commands
import time
import re
def ping_google():
ping = commands.getoutput('ping google.com -c5 -q')
if (re.search("[1-5] received",ping)):
print "Ping google succeeded"
return True
return False
def inet_restart():
print "Restarting internet"
os.system('/etc/rc.d/rc.inet1 stop')
time.sleep(10)
os.system('/etc/rc.d/rc.inet1 start')
count = 5
# ping google
# if there's a reply, end
# if not, wait 1 minute and try again
# after five tries, restart internet. sleep for 2 minutes
# if we've restarted the internet, repeat
while count == 5:
count = 0
# check for pong from google. check 5 times, or first response
while (not ping_google() and count < 5):
time.sleep(60)
count += 1
if count == 5: #can't get a hold of google within five minutes
inet_restart()
time.sleep(120)