Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get IP Address of Client Machine?

 
Usman Saeed
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
getRemoteAddr returns IP address of host machine but i want to get IP address of Client machine
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic