Solved

Getting client remote address

Posted on 2010-09-01
12
618 Views
Last Modified: 2013-11-23
Is there a way to get the client IP address when making  HTTP call ?. If a user types google.com i need to get the user IP address .
0
Comment
Question by:Micheal_Male
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33583868
0
 

Author Comment

by:Micheal_Male
ID: 33583904
The InetAddress.getLocalHost().getHostName() or .getAddress() gives me the server address or IP where my application is running not clients IP address who is making a call. Just like in access.log you see IP addresses logged in.

Creating a servlet will be of no use also because i would like to pass that IP Address to one of my method outside the servlet in a seperate JAR file which is deployed within the web application. I was looking for something without need of extending the HttpServlet class and writing doPost()method to get the IP address of the client.

 
0
 
LVL 10

Expert Comment

by:Hegemon
ID: 33584134
The only way to get client's IP address is to use a servlet (or JSP): request.getRemoteAddr();
You can then pass it to another location as you need.
0
 

Author Comment

by:Micheal_Male
ID: 33584164
hmmm. But still that servlet will be called only if a user goes to that servlet URL which in my senario fails only if it is possible to have a servlet which is called everytime a user access the web app ? like a lisetener or a filter ?.
0
 

Author Comment

by:Micheal_Male
ID: 33584168
There are no JSP only third party servlet configurations.
0
 
LVL 10

Expert Comment

by:Hegemon
ID: 33584177
Looks like a filter servlet is the best solution for you.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Micheal_Male
ID: 33584226
finally i found a way without creating a servlet after reading the spring docs.
0
 
LVL 2

Expert Comment

by:calboronster
ID: 33589708
A word of caution over here is that if the user is behind an ISP which is a fairly common thing then the HTTPServlet methods (and other methods relying on client calls) will return the ISP address and not the machine IP.

In a typical production scenario, when one of the banking sites was used from inside a closed organization, all the front-end users from different machines returned the same ISP host IPs.

In such a case, it is best to use an applet with call to InetAddress.getLocalHost().getHostName() etc.
Again this is not a very foolproof method and might require you to signed applet.

It is never a good and secure idea to get the users' local details.
Also it makes your application non-flexible.
0
 

Author Comment

by:Micheal_Male
ID: 33592392
I agree with you but the calls made to the http request are all going to be running on the same network but different terminals.
Just take an example of wallgreens who have a server. That server is connected to several cash registers. Eaxh cash register makes a call to the server to either store a transaction etc. So if you use inetaddresss.getlocalhost then it returns the server ip address not the terminal ip who made the call to the server.
0
 
LVL 2

Accepted Solution

by:
calboronster earned 250 total points
ID: 33600686
You didn't get my suggestion quite correclty.

In case you want an accurate IP address rather than an intermediate firewall etc IP, then
1. write a signed applet, that runs on individual browser.
2 make that applet get the InetAddress.getLocalHost().getHostName() etc.
3. Pass back the address to the server.
0
 

Author Comment

by:Micheal_Male
ID: 33602107
Applet is not a solution for me but thanks for your input. I got your point what you are trying to say.
0
 

Author Closing Comment

by:Micheal_Male
ID: 33602141
Nice explanation and suggestion.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now