5

怎么获取客户端真实的ip为

 3 years ago
source link: https://www.oschina.net/question/3644756_2324989
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

怎么获取客户端真实的ip为

jackfaye 发布于 01/24 20:24
阅读 927


请教一下,获取客户端真实ip为什么是这个逻辑顺序,首先获取x-forward-ip 而不是直接Proxy-Client-IP 

酷酷的就
01/25 11:51

主要是看web前面是否还有nginx等代理了,  你可以根据你的实际情况改这个顺序的

sprouting
01/27 09:14

靠这种代码获取真实IP还是有限制的,比如你前方做了代理,还要相关的参数也传递进来,否则可能会被代理改写

阳少
01/27 11:48

主要还是要看入口,对于真实IP,像这样通过hearder去取是可以伪造的

ducat7
01/27 13:40

网络,是由DNS构成

湖水没了
01/28 09:52

你这是一段危险的代码 客户端可以轻易欺骗你 给你传个头信息 你就得到假IP了

小塔罗
昨天 13:40
回复 @jackfaye : 使用x-forward-ip是最安全的就算用户给你传个假Header头你只需要再nginx反向代理的时候再把这个Header头设置成客户端的IP就行了
湖水没了
01/28 16:30
回复 @jackfaye : 用 request.getRemoteAddr() 获取ip,当前面有反向代理时增加tomcat配置 <Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeader="X-Forwarded-Proto"/> 让tomcat将真实ip放在remoteAddr里面

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK