CGI - client information

Will Stuyvesant hwlgw at hotmail.com
Sun Jan 5 14:48:42 EST 2003


[Jesper Olsen]
> Is it possible from a python cgi script to query the web server about
> the
> IP address of the client that is calling the script?
> 

Heh, Jesper Olsen, famous name, used to be a good soccer player at
Ajax and later an English team.

There are environment variables available in the CGI script::

  import os
  env = os.environ
  for key in ['REMOTE_ADDR', 'REMOTE_HOST', 'QUERY_STRING',
            'CONTENT_LENGTH', 'REMOTE_USER', 'REMOTE_IDENT']:
    print key+":",
    if env.has_key(key): print env[key]

If they send you a POST then there is CONTENT_LENGTH.  If they send
you a GET you have the QUERY_STRING.
Alas REMOTE_USER and REMOTE_IDENT usually are not available, I would
love to have them but I have no idea how to get those.

'''
Belief is no substitute for arithmetic. - Henry Spencer
'''




More information about the Python-list mailing list