Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import *
- import urllib.request
- import time
- #A function for checking the connectiviy with internet.
- #Return: If connection establishes, a urlopen handle otherwise None.
- def testconnection():
- try:
- f = urllib.request.urlopen("http://www.google.com")
- except:
- print("NOT OK")
- else:
- print("OK")
- return f
- while True:
- ff = testconnection()
- # check for the urlopen handle, if connection is not present follow this path,
- if(ff == None):
- print("No Internet Connection! Shutting Down System!")
- # works only in Windows; TODO extend for linux as well
- system("shutdown /s /t 100")
- exit(0)
- # If connection exist, then sleep for 15 minutes and loop back.
- else:
- print("InternetConnection Intact")
- time.sleep(15*60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement