views:

265

answers:

4

Hi,

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

+5  A: 

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

tangens
+1  A: 

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

James Black
A: 

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.

gustafc
A: 

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.

Nicholas Jordan