goldb.org home
 Thursday, April 03, 2008

Python - Script - Which Webserver Does That Site Run?

You can use this little Python function to see what type of web server a site is running.  All it does is send an HTTP request to the host and reads the 'server' header in the response.


import httplib

def get_server_type(host):
    conn = httplib.HTTPConnection(host)
    conn.request('GET', '/')
    resp = conn.getresponse()
    return resp.getheader('server')


print get_server_type('www.pylot.org')
print get_server_type('www.techcrunch.com')

Output:

lighttpd/1.4.19
Apache/2.0.52


Note: This doesn't work for all sites

#    Comments [7] |
Thursday, April 03, 2008 12:15:51 PM (Eastern Standard Time, UTC-05:00)
import urllib2
def get_server_type(host):
return urllib2.urlopen(host).info()['server'] # throws key error if it doesn't exist

# Or
urllib2.urlopen("http://www.facebook.com").info().getheader('server') # no key error if it doesn't exist
Thursday, April 03, 2008 2:00:56 PM (Eastern Standard Time, UTC-05:00)
You could use a HEAD request instead of a GET.
Thursday, April 03, 2008 2:08:38 PM (Eastern Standard Time, UTC-05:00)
I request HEAD all the time but rarely get it.


Sorry, I couldn't help myself.
Thursday, April 03, 2008 7:42:27 PM (Eastern Standard Time, UTC-05:00)
@grant:
HAHAHAHAHA

@Roberto:
Yeah a head request would be lighter weight, as it wouldn't actually download the page.
Friday, April 04, 2008 8:03:15 PM (Eastern Standard Time, UTC-05:00)
The shell script version:

http://bashcurescancer.com/shell-function-which-webserver-does-that-site-run.html
Saturday, April 05, 2008 2:23:56 PM (Eastern Standard Time, UTC-05:00)
@Brock: I was expecting a raw 'echo' to /dev/eth0 or something!!! Love the website name, freaking hilarious.
Saturday, April 05, 2008 2:37:37 PM (Eastern Standard Time, UTC-05:00)
And the Ruby version:

<a href = "http://www.benr75.com/articles/2008/04/05/web-server-type-determination-ruby-script">http://www.benr75.com/articles/2008/04/05/web-server-type-determination-ruby-script</a>
Name
E-mail
Home page

Comment (Some html is allowed: )  

Enter the code shown (prevents robots):