Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created April 27, 2010 10:06
Show Gist options
  • Save jiphex/380578 to your computer and use it in GitHub Desktop.
Save jiphex/380578 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import httplib
import sys
if len(sys.argv) < 3:
print "Usage: %s SERVER HOSTNAME[/REQUEST] [body?]" % sys.argv[0]
sys.exit(1)
else:
server = sys.argv[1]
host = sys.argv[2]
hc = httplib.HTTPConnection(server)
hc.request("GET", sys.argv[2])
resp = hc.getresponse()
hc.close()
if resp:
print "%d (%s) Response received over HTTP/%1.1f from %s:%d" % (resp.status, resp.reason, resp.version*0.1, hc.host, hc.port)
print "\n--Headers follow--"
for (hh,hv) in resp.getheaders():
print "%s => %s" % (hh,hv)
if(len(sys.argv) > 3):
print "\n--Body follows--"
print resp.read()
@jiphex
Copy link
Author

jiphex commented Apr 27, 2010

Connects to a specified HTTP server (SERVER) and then makes a request, bypassing DNS so you don't have to munge your /etc/hosts file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment