Advertisement
mvineetmenon

Python AutoShutdown v2

Apr 15th, 2013
1,757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from os import *
  2. from httplib import *
  3. from subprocess import *
  4. import time
  5. import platform
  6.  
  7. def testconnection():
  8.     f = HTTPConnection("www.google.com")
  9.     try:
  10.         f.request("GET", "/")
  11.         except Exception:
  12.         return False
  13.     return True;   
  14.  
  15.        
  16. while True:
  17.     ff = testconnection()
  18.     if(ff == False):
  19.         print("No Internet Connection! Shutting Down System!")
  20.         if(platform.system() == 'Windows'):
  21.             call(["shutdown","/s","/t","100"])
  22.         elif(platform.system() == 'Linux'):
  23.             call(["sudo", "poweroff"])
  24.         exit(0)
  25.     elif(ff == True):
  26.         print("InternetConnection Intact")
  27.                 print("Time to sleep some time")
  28.                 time.sleep(60*15)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement