用 Java 找出您网站访问者的 IP 地址
有没有简单可靠的方法来使用 Java 检测您的网站访问者 IP 地址。我正在尝试利用 Akismet 来检测我的博客文章/评论中的垃圾邮件。 API 要求我指定评论者的 IP 地址。
谢谢=)
Is there simple and reliable way to detect your website visitor IP address using Java. I am trying to make use of Akismet to detect spam on my blog post/comment. The API require me to specify the IP address of the commenter.
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
调用 ServletRequest.getRemoteAddr () 应该这样做。
A call to ServletRequest.getRemoteAddr() should do it.
ServletRequest.getRemoteAddr ()
在最简单的场景中执行此操作。如果您使用负载均衡器,则可能需要查看 X-Forwarded -对于标头,因为getRemoteAddr()
将是您的负载均衡器的地址。它是一个以逗号分隔的 IP 号码列表,其中最后一个是连接到负载均衡器的地址。最后一个地址是您唯一可以真正信任的地址(因为它将由负载均衡器添加),其他地址可能是欺骗性的。ServletRequest.getRemoteAddr()
does this in the simplest scenarios. If you're behind a load balancer, you may instead want to look at the X-Forwarded-For header, asgetRemoteAddr()
will be the address of your load balancer. It's a comma-separated list of IP numbers, where the last one is the address that connected to your load balancer. 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.如果你在服务器端使用JSP,那么你可以看这个链接:
http://www.rgagnon.com/javadetails/java-0363.html
如果您使用的是 servlet,那么您可以使用 HttpServletRequest.getRemoteAddr()
If you are using JSP on the server-side, then you can look at this link:
http://www.rgagnon.com/javadetails/java-0363.html
If you are using a servlet then you can use HttpServletRequest.getRemoteAddr()
问题流量大约是 80% 的人,他们会努力确保他们不做任何工作 - 我见过的每个保持正常运行的网站都使用某种人类不得不思考的身份验证,IPV4 是欺骗和入侵的持续来源和新闻报道(您不想参与其中) IPv6 通过工程级工作来解决这个问题。
到那时,我认为他们会转向使用人体盾牌或其他东西。
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.
At that point, I think they will move over to using human shields or something.