From: tbryan at zarlut.utexas.edu (Tom Bryan)
Date: Tue, 18 May 1999 06:46:46 -0500
Subject: Accessing REMOTE_ADDR from web page
References: <374112A2.9CC3B6F@qut.edu.au>
Message-ID: <37415326.F0CA811E@zarlut.utexas.edu>
Content-Length: 1220
X-UID: 1779                                                


Rico Albanese wrote:
 
> Can someone tell me how to access the REMOTE_ADDR shell environment
> variable which is sent with a web page request to a web server.  
[...detailed description and code cut...]
> My question is how do I access the REMOTE_ADDR??  Is "theenviron" a
> string,list, tuple what??

This is one of the places where the source is your friend!  I have 
found most of the Python library source code to be very clear.
On my machine, I have something like the following definition in 
cgi.py

def print_environ(environ=os.environ):
    """Dump the shell environment as HTML."""
    keys = environ.keys()
    keys.sort()
    print
    print "<H3>Shell Environment:</H3>"
    print "<DL>"
    for key in keys:
        print "<DT>", escape(key), "<DD>", escape(environ[key])
    print "</DL>" 
    print

Thus, you can see that the cgi script's "shell environment" is 
accessed just like the environment *always* is....through os.environ.
os.environ is a dictionary of all of the available environment 
variables.  Try printing os.environ['REMOTE_ADDR'].  Is that what you
were looking for?

-- 
tbryan at zarlut.utexas.edu
Remove the z from this address to reply.
Stop spam!  http://spam.abuse.net/spam/




