• Post Reply Bookmark Topic Watch Topic
  • New Topic

Returning the users IP address

 
rita mistry
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I was just wondering is there a method in JSP which will retrieve the user's IP address. Not the server's IP address but the IP address of the machine they are using.
Any help will be very much appreciated.
Many thanks
Rita.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to use javascript for that or other client side scripting language.
here is one example:
javascript ip user address
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roy Ben Ami:
you need to use javascript for that or other client side scripting language.
here is one example:
javascript ip user address

That's not quite true; a server has access to the IP address of the client that has connected to it. In the Java Servlet API, this information is represented to an application via the ServletRequest object. Thus, in a JSP page, you can call
request.getRemoteAddr()
to retrieve the IP address. In JSTL, you can avoid a scriptlet:
<c ut value="${pageContext.request.remoteAddr}"/>
Hope that helps.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i stand corrected
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need to remember that if the client is behind a firewall or proxy server, this IP address will most probably be that and not the clients machines address.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, NAT cam make every user on the network appear to be the same IP.
As if that wasn't enough, it's not that difficult to spoof IPs. If you were planning to use IPs for authentication - or even fine-grained request tracking - it's pretty hopeless.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!