• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ren Sha
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic