Finding out your website visitor IP address in Java

后端 未结 4 1054
眼角桃花
眼角桃花 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: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.

提交回复
热议问题