Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This scripts automatically polls the Google DNS server every 15 seconds to check that it has internet connectivity - It logs both LIVE and DEAD statuses to a formatted .csv file
- #Import required libraries
- import logging, time, socket, os, sys
- #Declare Variables
- ##Path to folder, leave it empty to put log files in executable folder
- folderpath=""
- count = 0
- ##Max number of iterations before it restarts itself - 5760 is roughly 24 hours
- maxCount = 5760
- #Configure Logging
- logging.basicConfig(filename=folderpath+time.strftime("%d%m20%y-%H%M%S",time.localtime())+".csv",level=logging.INFO,datefmt="%d %b - %Y : %H:%M:%S",format="%(asctime)s , %(levelname)s , %(message)s")
- console = logging.StreamHandler()
- console.setLevel(logging.INFO)
- formatter = logging.Formatter("%(asctime)s , %(levelname)s , %(message)s","%d %b - %Y : %H:%M:%S")
- console.setFormatter(formatter)
- logging.getLogger('').addHandler(console)
- while True:
- time.sleep(10)
- if count > maxCount:
- logging.shutdown()
- time.sleep(0.2)
- os.execv(sys.executable, ['python'] + sys.argv)
- else:
- try:
- time.sleep(5)
- count = count + 1
- s = socket.create_connection(("8.8.8.8", 53),5)
- logging.info(str(count)+" , LIVE")
- except:
- logging.warn(str(count)+" , DEAD")
Add Comment
Please, Sign In to add comment