IP Address Function

Piet van Oostrum piet at cs.uu.nl
Thu Jul 9 06:43:43 EDT 2009


>>>>> Fred Atkinson <fatkinson at mishmash.com> (FA) wrote:

>FA> On Wed, 08 Jul 2009 12:29:54 +0200, Piet van Oostrum <piet at cs.uu.nl>
>FA> wrote:

>>> Something like:
>>> 
>>> #! /usr/bin/env python
>>> 
>>> import cgi
>>> from os import getenv
>>> 
>>> print "Content-type: text/html"
>>> print
>>> 
>>> ipaddr = (getenv("HTTP_CLIENT_IP") or
>>> getenv("HTTP_X_FORWARDED_FOR") or
>>> getenv("HTTP_X_FORWARDED_FOR") or
>>> getenv("REMOTE_ADDR") or
>>> "UNKNOWN")
>>> 
>>> print ipaddr

>FA> That did it.  

>FA> I wonder why they don't just have a function to return it instead of
>FA> putting you through all of that?  

I see now that I had       getenv("HTTP_X_FORWARDED_FOR") or
duplicated.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list