LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to Find IPAddress of Client (https://www.linuxquestions.org/questions/programming-9/how-to-find-ipaddress-of-client-497227/)

duryodhan 10-31-2006 10:16 AM

How to Find IPAddress of Client
 
How do I write a JAVA servlet that will let me find the ip address of the client?

paulsm4 10-31-2006 12:47 PM

Just look up the inet address in the Socket object after you accept the connection:
http://java.sun.com/j2se/1.5.0/docs/...et/Socket.html

mrcheeks 10-31-2006 04:02 PM

You can also use the httpservletrequest methods. I think there is a remoteaddress method or something like it that you can use.

duryodhan 10-31-2006 09:52 PM

HttpServlet method getRemoteuser is present that gives login not ip.

Also I dont use a socket... I use HttpServletRequest and Response. Is that inherited from Socket?

If there is a simple way in asp.net then that will also do..

paulsm4 11-01-2006 12:31 AM

mrcheeks is absolutely correct. Look here:
http://www.oracle.com/technology/sam...lientInfo.html

duryodhan 11-01-2006 12:48 AM

Really sorry! Really stupid dumb thing I did. I looked at the HttpServletRequest API and forgot to check the inherited methods.

Thanks a lot ya all.

duryodhan 11-03-2006 11:28 PM

But the getRemoteAddr funtion returns ip of the last used proxy whereas I want the ipaddress of the actual user.
How do I do that?

arindam.lahiri 11-03-2006 11:45 PM

I dont think you will be able to get the real IP address of the client using the Java Http Servlet API. The request.getRemoteAddr() will give you the IP address of proxy server the client is behind.

mrcheeks 11-04-2006 10:53 AM

Quote:

Originally Posted by arindam.lahiri
I dont think you will be able to get the real IP address of the client using the Java Http Servlet API. The request.getRemoteAddr() will give you the IP address of proxy server the client is behind.

Usually there is variable set by the proxy which put the real ip adress in a header variable called something like client_ip. But it depends on the proxy, reverse-proxy, etc.

duryodhan 11-05-2006 12:49 AM

Check out whatsmyip. For me its able to show the ip assigned over the intranet too. i.e my router's ip(203.*.*.*) and my internal lan ip (172.16.*.*) . How is it able to do that? And it doesn't even seem to be loading a slow ass Java applet too.


All times are GMT -5. The time now is 11:07 AM.