473,473 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Finding web host headers

Is there any way to fetch a website's host/version headers using
Python?

Thanks,

Harlin

Jun 1 '06 #1
2 1282
> Is there any way to fetch a website's host/version headers using
Python?

import httplib
conn = httplib.HTTPConnection("docs.python.org")
conn.connect()
conn.request("HEAD", "/")
response = dict([(k.lower(), v) for k,v in conn.getresponse()])
conn.close()
server = response["server"]
print server

Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3
Python/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e
I've found a bit of discrepancy with regards to the case of the
"server" portion, so the above code just normalizes it to
lowercase and then shoves it in a dictionary.

You can then do as you please with the contents of the "server"
variable.

It's theoretically possible that the server can return differing
headers based on the URL you request or its method. You'll have
to adjust the request() call for the method (GET/HEAD/POST, etc)
and for the resource you want (in this case, just "/")

-tkc

Jun 1 '06 #2
>> Is there any way to fetch a website's host/version headers using
Python?

>>> import httplib
>>> conn = httplib.HTTPConnection("docs.python.org")
>>> conn.connect()
>>> conn.request("HEAD", "/")
>>> response = dict([(k.lower(), v) for k,v in conn.getresponse()])
>>> conn.close()
>>> server = response["server"]
>>> print server Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3
Python/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e


Dang, I copied that over by hand and miscopied it with a big
error or two. It can also be cleaned up a bit, as I learned (the
getheader() call is case-insensitive, and the connect() call was
superfluous). Copying verbatim...
import httplib
conn = httplib.HTTPConnection("docs.python.org")
conn.request("HEAD", "/")
response = conn.getresponse()
conn.close()
server = response.getheader("server")
print server

Apache/2.0.54 (Debian GNU/Linux) DAV/2 SVN/1.1.4 mod_python/3.1.3
Python/2.3.5 mod_ssl/2.0.54 OpenSSL/0.9.7e

Sorry about the rubbish code the first time out the gate.

-tkc
Jun 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Geoff Berrow | last post by:
The host of one of the domains I manage has installed 4.3.11-dev and as a result file uploads no longer work with Internet Explorer. Worth keeping an eye out for. In the meantime I now need to...
2
by: Andy | last post by:
Hello Group: How would I go about connecting to an IIS server and getting a list of the host headers for a certain web-site? I am not sure where to begin or how to go about doing this. I...
3
by: Karl Easterly | last post by:
Hi. I have a site running with a FQDN which is addressed using host headers. Instead of working with the project through a mapped drive, I would like to work with it via the concept implied as...
0
by: greg | last post by:
we need to add host headers to a IIS site (not default one) in .NET/c# we can print host headers but cannot insert programmatically new one bellow is our code
3
by: Tim_Mac | last post by:
hi, see quote below from http://groups.google.ie/groups?hl=en&lr=&th=36c5d2df211a4d78&seekm=00480961-660F-462D-BBD4-455C8DA26C38%40microsoft.com&frame=off According to the book: "Deploying .NET...
2
by: suchismita.83 | last post by:
Hi, I want to fetch host header of a site url but not getting idea how to do that. Can we do by using HttpRequest.ServerVariables. I have searched in net but not getting the member through which...
0
by: Gabriel Genellina | last post by:
En Mon, 14 Apr 2008 01:04:40 -0300, Penny Y. <pylists@arcor.deescribió: Add a `headers` parameter to the request method. See http://docs.python.org/lib/httpconnection-objects.html Something...
3
by: teddarr | last post by:
I have a Windows Server 2003. I am trying to run multiple websites on the server. I have 3 different websites I'd like to run. Currently the default website is working but no others. All...
0
by: teddarr | last post by:
I have a Windows Server 2003. I am trying to run multiple websites on the server. I am using host headers to run the websites on only one ip address. Before anyone says this is an iis issue and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.