简体   繁体   English

关于在python CGI中获取客户端ip地址

[英]about get client ip address in python CGI

I am trying to get the original client ip address in a python cgi script. 我正在尝试在python cgi脚本中获取原始客户端IP地址。 The client connect to the web server with a proxy. 客户端使用代理连接到Web服务器。 Following code always returns the proxy ip address. 以下代码始终返回代理IP地址。 I tested all the env variable, HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR all return None. 我测试了所有环境变量,HTTP_CLIENT_IP和HTTP_X_FORWARDED_FOR全部返回None。 Is there any other way to get the client ip behind a proxy? 还有其他方法可以使客户端ip成为代理服务器吗? like can I read the http header in a python cgi? 像我可以在python cgi中读取http标头吗?

ipaddr = (getenv("HTTP_CLIENT_IP") or
getenv("HTTP_X_FORWARDED_FOR") or
getenv("REMOTE_ADDR") or
"UNKNOWN")

Do you want to: 你想要_____吗:

  • find the client's IP address in the headers 在标题中找到客户端的IP地址

  • use some sort of javascript to tell you? 用某种JavaScript来告诉你?

For the former, you need the proxy to give you the client address. 对于前者,您需要代理才能为您提供客户地址。
Have you tried cgi.print_environ_usage() and looking for the IP address? 您是否尝试过cgi.print_environ_usage()并寻找IP地址?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM