aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes How to trace Client IP address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to trace Client IP address" Watch "How to trace Client IP address" New topic
Author

How to trace Client IP address

Sam Jimzz
Greenhorn

Joined: Apr 30, 2011
Posts: 28

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..?


God Loves You and will never love you less.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Apr 30, 2011
Posts: 28

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

Joined: Oct 27, 2005
Posts: 19670
    
  18

Then you must set up your load balancers to forward the actual client's IP address.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sam Jimzz
Greenhorn

Joined: Apr 30, 2011
Posts: 28

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Apr 30, 2011
Posts: 28

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
You need to have a chat with your server admin, then.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to trace Client IP address