Finding out your website visitor IP address in Java

后端 未结 4 1046
眼角桃花
眼角桃花 2021-01-25 06:05

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

相关标签:
4条回答
  • 2021-01-25 06:48

    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()

    0 讨论(0)
  • 2021-01-25 06:51

    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, as getRemoteAddr() 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.

    0 讨论(0)
  • 2021-01-25 06:56

    A call to ServletRequest.getRemoteAddr() should do it.

    0 讨论(0)
  • 2021-01-25 06:56

    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.

    0 讨论(0)
提交回复
热议问题