0

We can get client IP address from Request object as follows:

 String ipAddress = request.getRemoteAddr();

But, if the user is behind a proxy server or access your web server through a load balancer, the above code will get the IP address of the proxy server or load balancer server, not the original IP address of a client.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
sourav banik
  • 11
  • 2
  • 3
  • So this is a proxy, NAT etc for. No way to get the client IP(s) on the local network, if the client doesn't send it as payload. – PeterMmm Jan 19 '17 at 07:16
  • The only way is to ask the client see http://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript-only – Scary Wombat Jan 19 '17 at 07:16
  • Why? and don't forget, ip adresses can be spoofed, and if it's routed via onion it's for intents and purposes impossible to trace back. – Tschallacka Jan 19 '17 at 07:16

1 Answers1

0

If we are talking about HTTP requests, you may try the following:

String strForwardedFor = httpServletRequest.getHeader("X-Forwarded-For");

If the proxy sets this header, it should look like:

client-ip,proxy1-ip,proxy2-ip,...
Olaf Ziems
  • 69
  • 8
  • 1
    Remember that this header can be easily spoofed. You can only trust the ones you know. (See Shane Madden's answer in http://security.stackexchange.com/questions/24197/is-it-possible-to-spoof-the-last-proxy-of-an-x-forwarded-for-header) – KC Wong Jan 19 '17 at 07:24