Created
July 27, 2010 10:16
-
-
Save fwenzel/492020 to your computer and use it in GitHub Desktop.
Test script for Bouncer GeoIP
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
#!/usr/bin/env python | |
import httplib | |
import urllib | |
from urlparse import urlparse | |
BOUNCER_URL = 'http://fwenzel.khan.mozilla.org/bouncer-tuxedo/' | |
PRODUCT = 'Firefox-3.6.8' | |
TEST_IP = '' # Use an IP from the region you want to test | |
USE_X_FORWARDED_FOR = True | |
NUM_TRIES = 10000 # Amount of times to repeat the test | |
def test_geoip(): | |
parsed = urlparse(BOUNCER_URL) | |
conn = httplib.HTTPConnection(parsed.netloc) | |
if not USE_X_FORWARDED_FOR: | |
test_data = urllib.urlencode({'product': PRODUCT, 'ip': TEST_IP}) | |
headers = None | |
else: | |
test_data = urllib.urlencode({'product': PRODUCT}) | |
# Some fake proxies | |
headers = {'X-Forwarded-For': '%s, 127.0.0.1, 192.168.0.1' % TEST_IP} | |
targets = {} # remember redirect targets | |
for i in xrange(NUM_TRIES): | |
conn.request('HEAD', '%s?%s' % (parsed.path, test_data), | |
headers=headers) | |
resp = conn.getresponse() | |
if not resp.status == 302: | |
print "ZOMG: %d" % resp.status | |
else: | |
loc = resp.getheader('Location', '') | |
targets[loc] = targets.setdefault(loc, 0) + 1 | |
return targets | |
if __name__ == "__main__": | |
targets = test_geoip() | |
targetlist = [t for t in targets.items()] | |
targetlist.sort(key=lambda t: t[1], reverse=True) | |
for t in targetlist: | |
print '%s: %d times' % t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment