import httplib2 import subprocess import time import dns.resolver tests = [ {"host": "cdn.example.com", "path": "/path/to/somebigfile.js", "ip": "x.x.x.x"}, {"host": "cdn2.example.com", "path": "/path/to/somebigfile.js", "ip": None}, ] for testfile in tests: res = res = dns.resolver.Resolver() if testfile["ip"] is None: ip = res.query(testfile["host"])[0].address else: ip = testfile["ip"] url = "http://%s%s" %(ip, testfile["path"]) print ip, url dumpc = "tcpdump host %s > %s.txt" %(ip, testfile["host"]) print dumpc p = subprocess.Popen(["tcpdump", "-w", "%s.cap" %( testfile["host"]), "-s", "0", "host", ip ], stdout=subprocess.PIPE) print p time.sleep(2) h = httplib2.Http() resp, origin = h.request(url, headers={'Host':testfile['host'] , 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1'}) h = None print resp time.sleep(5) p.terminate()