• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Returning the users IP address

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i stand corrected
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I am a man of mystery. Mostly because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic