简体   繁体   English

用Java查找您的网站访问者IP地址

[英]Finding out your website visitor IP address in Java

Is there simple and reliable way to detect your website visitor IP address using Java. 有没有简单可靠的方法可以使用Java检测您的网站访问者IP地址。 I am trying to make use of Akismet to detect spam on my blog post/comment. 我试图利用Akismet在我的博客文章/评论中检测垃圾邮件。 The API require me to specify the IP address of the commenter. 该API要求我指定评论者的IP地址。

Thanks =) 谢谢=)

调用ServletRequest.getRemoteAddr()应该可以做到。

ServletRequest.getRemoteAddr() does this in the simplest scenarios. ServletRequest.getRemoteAddr()在最简单的情况下执行此操作。 If you're behind a load balancer, you may instead want to look at the X-Forwarded-For header, as getRemoteAddr() will be the address of your load balancer. 如果您在负载均衡器后面,则可能需要查看X-Forwarded-For标头,因为getRemoteAddr()将是负载均衡器的地址。 It's a comma-separated list of IP numbers, where the last one is the address that connected to your load balancer. 这是一个用逗号分隔的IP编号列表,其中最后一个是连接到负载均衡器的地址。 The last address is the only one you can really trust (as it will be added by the load balancer), the others may be spoofed. 最后一个地址是您真正信任的唯一地址(因为它将由负载均衡器添加),其他地址可能会被欺骗。

If you are using JSP on the server-side, then you can look at this link: http://www.rgagnon.com/javadetails/java-0363.html 如果您在服务器端使用JSP,则可以查看以下链接: http : //www.rgagnon.com/javadetails/java-0363.html

If you are using a servlet then you can use HttpServletRequest.getRemoteAddr() 如果使用的是Servlet,则可以使用HttpServletRequest.getRemoteAddr()

Problem traffic is about 80% folks who will work to be sure they do not do work - every site that I have seen that stays up uses some sort of human-has-to-think authentication, IPV4 is a constant source of spoofing, intrusions, and news reports ( which you want to stay out of ) IPv6 approaches the matter with engineering-grade work. 有问题的流量大约有80%的人会努力确保他们不会工作-我见过的每个站点都处于停滞状态,使用了某种人类可以想到的身份验证,IPV4一直是欺骗,入侵的源头。 ,以及新闻报道(您希望远离新闻报道),IPv6通过工程级的工作来解决此问题。

At that point, I think they will move over to using human shields or something. 到那时,我认为他们将使用人盾或其他工具。

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

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