This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes IP address retrieval Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "IP address retrieval " Watch "IP address retrieval " New topic

IP address retrieval

sunil kumre
Ranch Hand

Joined: Dec 23, 2000
Posts: 64
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
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236

You can make use of the method getRemoteAddr() declared in the
ServletConfig interface,implemented by HttpServletRequest class
This method will return the string equivalent of the client
IP address.The firewall shouldn't be a problem.
Hope this helps,
I agree. Here's the link:
subject: IP address retrieval
jQuery in Action, 3rd edition