Skip to content

Instantly share code, notes, and snippets.

@jwoschitz
Created January 23, 2012 18:10
Show Gist options
  • Save jwoschitz/1664597 to your computer and use it in GitHub Desktop.
Save jwoschitz/1664597 to your computer and use it in GitHub Desktop.
Simple Http check utility
import httplib
import time
def get_current_time():
return time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
def get_connection(domain, port):
if port == httplib.HTTPS_PORT:
return httplib.HTTPSConnection(domain)
return httplib.HTTPConnection(domain)
def send_get_request(domain, uri, port):
try:
connection = get_connection(domain, port)
connection.request("GET", uri)
response = connection.getresponse()
print get_current_time() + " | " + domain + ":" + str(port) + " " + str(response.status) + " " + response.reason
except:
print get_current_time() + " error in connecting to " + domain + uri
def check_url():
send_get_request("www.google.de","", httplib.HTTP_PORT)
send_get_request("secure.img-cdn.mediaplex.com","/0/8541/138140/mp_landing_ns.js", httplib.HTTPS_PORT)
time.sleep(30)
check_url()
check_url()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment