Newbie-question: Fetching web-address from the browser!

Alan Kennedy alanmk at
Fri Sep 12 12:25:47 CEST 2003

dermoon wrote:
> I want to fetch the address from the web-browser when it
> visits a page on my web-server.

Hmmm, what exactly do you mean by the "address from the web-browser".
Possibilities include (with solutions for CGI scripts)

1. The IP address of the remote machine, i.e. the numerical address of
computer on which the browser is running?

If yes, try the "REMOTE_ADDR" environment variable, like so

import cgi, os
remote_addr = os.environ['REMOTE_ADDR']

2. The name of the remote machine on which the browser is running,
e.g. ''? If yes, do a reverse DNS
lookup on the IP address discovered above, like so

import cgi, os, socket
remote_addr = os.environ['REMOTE_ADDR']
remote_name = socket.gethostbyaddr(remote_addr)[0]

3. The address of the web page that contained a link to your page,
i.e. the "HTTP Referer"? If yes, take a look at the "HTTP_REFERER"
environment variable, like so

import cgi, os
referer_url = os.environ['HTTP_REFERER']

Note that not all browsers supply the "referer" header, and some
firewalls/proxies drop it, for privacy reasons.

Is any of these what you meant? Or did you mean something else?

alan kennedy
check http headers here:
email alan:    

More information about the Python-list mailing list