Created
July 7, 2017 19:13
-
-
Save k4kfh/ab3dac5fc180e7be9eaca83208837f38 to your computer and use it in GitHub Desktop.
This script will make HTTP requests on a regular basis and log any errors to a file with a timestamp. Useful for testing proxies.
This file contains 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
# PROXY TESTER | |
# Run this script with an array of URLs and it will make HTTP requests. Whenever it encounters an error it will timestamp it and log it | |
#import libs | |
import urllib2 | |
import hashlib | |
import sys | |
import time | |
import datetime | |
#config | |
testURLlist=["http://8.8.8.8","http://google.com"] | |
timestamp="" | |
timeToWait=60 | |
while True: | |
print("Beginning iterative tests...") | |
for testURL in testURLlist: | |
print("Testing %s...") % testURL | |
try: | |
#get the timestamp for right now | |
timestamp=datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') | |
httpResponse=urllib2.urlopen(testURL) | |
except: | |
print("Received Error for test!", testURL, sys.exc_info()[0]) | |
#file logging code | |
with open("http-test-errorlog.txt","a+") as logfile: | |
logfile.write(timestamp + " Received error for test of " + testURL + "\n") | |
else: | |
print("Success! Recieved response from %s") % testURL | |
shaHash = hashlib.sha224(httpResponse.read()).hexdigest() | |
print("Response SHA224 Hash: %s") % shaHash | |
time.sleep(timeToWait) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment