• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to trace Client IP address

 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i trace the users IP address from a web application.. i tried with some existing methods in java. but its showing servers ip address..

How can i solve it..?
 
Tim Moores
Bartender
Posts: 2748
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HttpServletRequest object has methods to get the remote IP address. If you get "127.0.0.1" or some other local IP address, ask your server admin whether there's some kind of forwarding going on (also google for "x-forwarded-for" in that case).
 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:The HttpServletRequest object has methods to get the remote IP address. If you get "127.0.0.1" or some other local IP address, ask your server admin whether there's some kind of forwarding going on (also google for "x-forwarded-for" in that case).


yes..i tried with 2-3 methods in HttpServletRequest. but still in vain. we have two servers for balancing the load,while executing the code,its just retrieving the proxy address.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you must set up your load balancers to forward the actual client's IP address.
 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Then you must set up your load balancers to forward the actual client's IP address.


Is there any other way(3rd party packages,api) to catch the IP address without disturbing load balancers config.?
 
Tim Moores
Bartender
Posts: 2748
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The use of x-forwarded-for is the standard way to do this. Have you checked that it's not being used (and thus available to your servlet) already?
 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:The use of x-forwarded-for is the standard way to do this. Have you checked that it's not being used (and thus available to your servlet) already?

Yes i tried with the following code.,

But still getting the same address(server IP)..
 
Tim Moores
Bartender
Posts: 2748
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have a chat with your server admin, then.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic