• Post Reply Bookmark Topic Watch Topic
  • New Topic

client IP address  RSS feed

 
FY Hsieh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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 ?
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with ServletRequest.getRemoteAddr()?
 
FY Hsieh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • 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.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use ServletRequest.getRemoteAddr()..
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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 is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!