Created
December 5, 2014 23:03
-
-
Save russau/63f8d8dcbfbcfc2a8418 to your computer and use it in GitHub Desktop.
s3 redirect diagnose
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
import urllib2 | |
import datetime | |
import time | |
import socket | |
domain = "201412051453-oregon-cats.s3.amazonaws.com" | |
# http://stackoverflow.com/questions/17202364/urllib2-urlopen-adding-host-header | |
while 1: | |
with open("hitter_log", "a") as myfile: | |
try: | |
ip = socket.gethostbyname(domain) | |
url = 'http://' + ip + "/cat1.jpeg" | |
headers = { 'Host' : domain } | |
req = urllib2.Request(url, None, headers) # make POST request to url with data and headers | |
response = urllib2.urlopen(req) # get the response from the server | |
log = "{:%Y-%m-%d %H:%M:%S} {} {} \n".format(datetime.datetime.now(), ip, response.geturl()); | |
print(log) | |
myfile.write(log) | |
except socket.gaierror as e: | |
log = "socket error({0}): {1}\n".format(e.errno, e.strerror) | |
print log | |
myfile.write(log) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment