Obtaining the remote ip address

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Mar 28 09:15:51 CEST 2006


"Alvin A. Delagon" <adelagon at gmail.com> writes:

> I have a python cgi script running behind a CGI server which is also 
> built using python using CGIHTTPServer module. How can my cgi script 
> obtain the remote ip address?

The CGI specification lists a number of environment variables that are
set for the scrit receiving the request. The one you want is
REMOTE_ADDR, and possibly REMOTE_HOST.

    <URL:http://hoohoo.ncsa.uiuc.edu/cgi/env.html>

Python makes environment variables available via the 'os.environ' map.

    <URL:http://docs.python.org/lib/os-procinfo.html>

-- 
 \     "I cannot conceive that anybody will require multiplications at |
  `\    the rate of 40,000 or even 4,000 per hour ..."  -- F. H. Wales |
_o__)                                                           (1936) |
Ben Finney




More information about the Python-list mailing list