File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Difference between request.getRemoteAddr() and request.getLocalAddr()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between request.getRemoteAddr() and request.getLocalAddr()?" Watch "Difference between request.getRemoteAddr() and request.getLocalAddr()?" New topic
Author

Difference between request.getRemoteAddr() and request.getLocalAddr()?

Ren Sha
Greenhorn

Joined: Mar 08, 2012
Posts: 9
Hi friends,

I need to get the client IP so i was using getRemoteAddr() then one of my friend told me i need to use getLocalAddr() instead of this(the first one was working fine).
When i read the description i'm bit confused about getLocalAddr(), from the description i understand it'll returns IP of the interface on which the request was received.
It won't be client IP, right? Is it the server IP?

Please help me
Christian Ludt
Greenhorn

Joined: Apr 07, 2009
Posts: 11
Hi Ren,

getRemoteAddr() is what you need to use:

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.


getLocalAddr() returns the IP of the server the application is running on.
Ren Sha
Greenhorn

Joined: Mar 08, 2012
Posts: 9
Thanks!
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4650
    
    5

Just be careful, the remote IP address may or may not be the address of the client. And when the client is using DHCP (which most folks do) then the IP address can and will change during the session.
 
Consider Paul's rocket mass heater.
 
subject: Difference between request.getRemoteAddr() and request.getLocalAddr()?