jQuery in Action, 2nd edition
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
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply 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: 13

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: 2329
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: 13

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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18368

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


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

Joined: Apr 30, 2011
Posts: 13

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: 2329
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: 13

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: 2329
You need to have a chat with your server admin, then.
 
 
subject: How to trace Client IP address
 
Threads others viewed
IP address
client IP address
Java /Oracle (IPAddress)
ip address ?
PC IP address
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture