Created
January 23, 2012 18:10
-
-
Save jwoschitz/1664597 to your computer and use it in GitHub Desktop.
Simple Http check utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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