Check if internet is detected. If not, restart the computer.
def check_internet(): try: response = urllib2.urlopen('http://google.com',timeout=1) return True except urllib2.URLError as err: pass return False if check_internet() == False: os.system("shutdown /r /t 1")