server = 'www.google.com' ## provide your server/website here ## import os import subprocess import ctypes import sys def alert(arg): sys.stderr.write("%d%d%d" % (arg, arg, arg)) cmd = 'ping '+server obj=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) result,error=obj.communicate() if error: print(error) else: RESULT = result if 'Request timed out' in RESULT or 'Could not reach destination host' in RESULT or 'Ping request could not find host' in RESULT: print(server+ ' is offline') alert(1) else: print(server +' is online') alert(0)