-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (34 loc) · 898 Bytes
/
main.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
try:
import httplib
except:
import http.client as httplib
import time
from subprocess import Popen
# Time interval to check connection
CHECKING_INTERVAL = 5
def have_internet():
"""
Checks if the computer has a connection to the internet.
:return: True if there is a successful connection to google servers, False otherwise.
"""
conn = httplib.HTTPConnection("www.google.com", timeout=5)
try:
conn.request("HEAD", "/")
conn.close()
return True
except:
conn.close()
return False
def main():
while True:
if have_internet():
# We have internet connection
print("Connected!")
else:
p = Popen("autodial.bat")
stdout, stderr = p.communicate()
print(stdout)
print(stderr)
time.sleep(5)
if __name__ == '__main__':
main()