• Post Reply Bookmark Topic Watch Topic
  • New Topic

IP address retrieval  RSS feed

 
sunil kumre
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I'm writing a servlet which will be put on our server.
A client can make a request for this servlet.I would like to retrieve the IP address of the client machine(which could be behind a firewall).What code should be put in the servlet to make this happen.
Thanks in advance
Sunil
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's one of the http headers - REMOTE_ADDR. However, it's not reliable for general use - it can be spoofed, translated, or otherwise removed or tampered with. Check the servlets forum and you'll see a fairly detailed discussion that went on about this a week or so back.
 
Jolly Jumper
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I used HttpServletRequest.getRemoteHost() and it worked fine (LAN). However, I'm not sure if it can achieve the machine's ip behind firewall.
Please check it
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jolly Jumper",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
Dave.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that the getRemoteHost() necessarily fails - just that due to previously-mentioned IP-mangling processes, IPs are not reliable identifiers.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!