• 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

client IP address

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have an application server hosting j2ee applications. Suppose a client machine uses Java URLConnection
to access one of our application page, is there a way for our server to find out the IP address of that client ?
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you familiar with ServletRequest.getRemoteAddr()?
 
FY Hsieh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Johnson:
Are you familiar with ServletRequest.getRemoteAddr()?



Well, I am thinking about this -- if none of my applications implements this or such methods in the application themselves, is there a way for me to tell by checking the web or system logs ?
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


if none of my applications implements this



Your application doesn't implement this method. The container does. Your servlet is passed a request object when the container invokes it. That request object has a method called getRemoteAddr().



is there a way for me to tell by checking the web or system logs



Yes, the web server or app server may be writing a log with the client IP. That depends on how your environment is configured. If you are simply debugging your app, looking in the log is ok. If your app needs the information, scanning a log isn't an elegant solution. Use getRemoteAddr().
[ December 18, 2006: Message edited by: Scott Johnson ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Johnson:
Are you familiar with ServletRequest.getRemoteAddr()?



This will work if there is not proxy in between the client and the server.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and only if the serverside application is a servlet or JSP...
Can't call that thing from an EJB for example.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This will work if there is not proxy in between the client and the server.



Yes, if the client request is passing through one or more proxy servers, the app server will see the IP address of the last proxy.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use ServletRequest.getRemoteAddr()..
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Neerav Narielwala:
Use ServletRequest.getRemoteAddr()..



Here we are already talking about the same. Kindly spend some time to read the post carefully. Thanks.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not really expert in JavaScript but how about if use document.URL or document.location.href and store that in some hidden fields. How it sounds? It wouldn't work with JavaScript disabled, indeed. Just a thought.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


how about if use document.URL or document.location.href



FY is looking for the client IP not the server url.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Scott Johnson:
FY is looking for the client IP not the server url.



Oops! My mistake. I mixed up it all. May be i was not in my senses.
Thanks.
 
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic