aspose file tools*
The moose likes JSP and the fly likes How to get IP Address of Client Machine? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get IP Address of Client Machine?" Watch "How to get IP Address of Client Machine?" New topic
Author

How to get IP Address of Client Machine?

Usman Saeed
Ranch Hand

Joined: May 21, 2008
Posts: 31
Hello,
I am using jsp,javascript and want to get IP address of client machine. My application will run on local network, not on internet.
Thanks


Usman Saeed
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
The HttpServletRequest object -which is available in JSP pages as "request"- has the getRemoteAddr method that returns the client IP address.


Ping & DNS - updated with new look and Ping home screen widget
Usman Saeed
Ranch Hand

Joined: May 21, 2008
Posts: 31
Hi,
getRemoteAddr returns IP address of host machine but i want to get IP address of Client machine
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No, getRemoteAddr gets the address of the client machine,
getLocalAddr gets the address of the host machine.


getRemoteAddr

public java.lang.String getRemoteAddr()

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.

Returns:
a String containing the IP address of the client that sent the request



[ May 27, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39530
    
  27
I think you're mistaken. It may be that the value is not correct after the request went through a NATed firewall or a server in front of the servlet container (like an Apache httpd); in that case, talk to the sysadmins how you to get at the client IP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get IP Address of Client Machine?
 
Similar Threads
How to get Mac Id of my client machine
LAN ID from the servlet
Port Number while starting the server
How to get the IP address of machine where the jsp file is opened
How to get the IP address of machine where the jsp file is opened