473,800 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
+ 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 1296
> Is there any way to fetch a website's host/version headers using
Python?

import httplib
conn = httplib.HTTPCon nection("docs.p ython.org")
conn.connect()
conn.request("H EAD", "/")
response = dict([(k.lower(), v) for k,v in conn.getrespons e()])
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.HTTPCon nection("docs.p ython.org")
>>> conn.connect()
>>> conn.request("H EAD", "/")
>>> response = dict([(k.lower(), v) for k,v in conn.getrespons e()])
>>> 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.HTTPCon nection("docs.p ython.org")
conn.request("H EAD", "/")
response = conn.getrespons e()
conn.close()
server = response.gethea der("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
1934
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 ask why they have installed a development version on a production server... -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies.
2
1458
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 have tried some google searches, but nothing so far is helping. Thanks Andy
3
1534
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 'open->project from web'. I have no problem working with it via the mapped drive, even debuggin is fine. I am sure it is a simple setting I need to toggle, but I do not know which. I tried web sharing the folder but when I open in this mannor I
0
1186
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
2982
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 Applications Lifecycle Guide" published in Microsoft Press: "Web setup projects allow you to specify which port to install the application on, they do not currently support deployment of a Web application to a site differentiated by host...
2
2636
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 we can fetch the hosturl using these "servervariables". Can anyone help me out how to fetch the root level url of a site. TIA
0
924
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 like this (untested): headers = {'Host', 'the.host.name'} conn = httplib.HTTPConnection("192.168.1.1") conn.request("GET", "/", headers=headers)
3
4532
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 the domains have an a record pointing to the network router. The router is conficured correctly to send all website requests to my server. One the server and for each website I went to the IIS manager on the Websites tab and have the IP address set...
0
2450
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 in the wrong forum, Please note that I have tested all the host header settings with a simple hello world html file and everything works great. I get a runtime error that tells me to change custom errors to "Off". The main problem is that custom...
1
10250
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.