使用python获取客户端ip
我是python的新手。 我想写一个简单的网页,在屏幕上打印客户端ip 我的http.conf处理程序: AddHandler mod_python.py PythonHandler mod_python.publisher 蟒蛇 cgi.escape(os.environ[“REMOTE\u ADDR”])返回此错误:KeyError:'REMOTE\u ADDR' 我只是迷路了BaseHTTPRequestHandler 那么,获取客户端ip的简单方法是什么?使用python获取客户端ip,python,apache,webserver,mod-python,Python,Apache,Webserver,Mod Python,我是python的新手。 我想写一个简单的网页,在屏幕上打印客户端ip 我的http.conf处理程序: AddHandler mod_python.py PythonHandler mod_python.publisher 蟒蛇 cgi.escape(os.environ[“REMOTE\u ADDR”])返回此错误:KeyError:'REMOTE\u ADDR' 我只是迷路了BaseHTTPRequestHandler 那么,获取客户端ip的简单方法是什么? 谢谢。好的,我找到了答案: f
谢谢。好的,我找到了答案:
from mod_python import apache
def client_ip(req):
req.add_common_vars()
return req.subprocess_env['REMOTE_ADDR']
它起作用了 如果您担心可伸缩性,这可能会快一点:
from mod_python import apache
req.get_remote_host(apache.REMOTE_NOLOOKUP)