Have The Address Of The Client In Python
Solution 1:
You can use cgi
and REMOTE_ADDR
and use like this :
cgi.escape(os.environ["REMOTE_ADDR"])
Put that in a variable and call the variable into action of your html form ....
Solution 2:
The IP of the client (which I assume is what you mean by "address of the client") is passed to your server at the TCP/IP level. If you are using CGI (which seems to be the case according to some info hidden in your comments and not stated in your question), it should be available to the CGI script environment as REMOTE_ADDR
(cf http://www.ietf.org/rfc/rfc3875, section 4.1.8). In Python, the way to access environment variables is to use os.environ
(https://docs.python.org/2/library/os.html#os.environ).
Note that since the CGI script will have access to this address, you don't need to add it to the URL, querystring or (in the case of a POST or PUT request) request's body.
Also note that if your server is accessed thru a proxy, load balancer or whatever, the REMOTE_ADDR might not be the real client IP and you may have to check the HTTP request's headers for a X-Forwarded-For
header, cf http://en.wikipedia.org/wiki/X-Forwarded-For. This header (if positionned) should be accessible in the same way as REMOTE_ADDR
or any other request header, but possibly renamed as HTTP_X_FORWARDED_FOR
, cf http://www.ietf.org/rfc/rfc3875.txt sections 4.1 and 4.1.18.
Post a Comment for "Have The Address Of The Client In Python"