Script to get HTTP Headers

The below script uses urllib2 to connect to the given URL(s) then prints out the HTTP headers.

http-server-header.py

#:/bin/python
import urllib2, sys

if len(sys.argv) == 1:
    print "Please feed me a URL...\n\n<3\n"
    sys.exit(0)

for url in sys.argv[1:]:
    r = urllib2.urlopen(url)
    print 'URL: ' + url + '\n' + str(r.info())

An example of it working is shown below. From a “security through obscurity” view, you’d want to conceal your HTTP server information.

$ python ~/http-server-header.py http://nationpigeon.com
    URL: http://nationpigeon.com
    Server: nginx/1.2.1
    Date: Mon, 05 Aug 2013 01:10:19 GMT
    Content-Type: text/html
    Content-Length: 650
    Last-Modified: Mon, 29 Jul 2013 08:46:57 GMT
    Connection: close
    Accept-Ranges: bytes