File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 34
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: 42936
    
  68
The HttpServletRequest object -which is available in JSP pages as "request"- has the getRemoteAddr method that returns the client IP address.
Usman Saeed
Ranch Hand

Joined: May 21, 2008
Posts: 34
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: 42936
    
  68
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.
 
 
subject: How to get IP Address of Client Machine?