LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-31-2006, 10:16 AM   #1
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Rep: Reputation: 46
How to Find IPAddress of Client


How do I write a JAVA servlet that will let me find the ip address of the client?
 
Old 10-31-2006, 12:47 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 10-31-2006, 04:02 PM   #3
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 50
You can also use the httpservletrequest methods. I think there is a remoteaddress method or something like it that you can use.
 
Old 10-31-2006, 09:52 PM   #4
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
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..
 
Old 11-01-2006, 12:31 AM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
mrcheeks is absolutely correct. Look here:
http://www.oracle.com/technology/sam...lientInfo.html
 
Old 11-01-2006, 12:48 AM   #6
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
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.
 
Old 11-03-2006, 11:28 PM   #7
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
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?
 
Old 11-03-2006, 11:45 PM   #8
arindam.lahiri
LQ Newbie
 
Registered: Aug 2004
Location: Allahabad, Uttar Pradesh, India.
Distribution: Fedora Core and Red Hat Linux
Posts: 15

Rep: Reputation: 0
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.

Last edited by arindam.lahiri; 11-04-2006 at 12:27 AM.
 
Old 11-04-2006, 10:53 AM   #9
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 50
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.
 
Old 11-05-2006, 12:49 AM   #10
duryodhan
Senior Member
 
Registered: Oct 2006
Distribution: Slackware 12 Kernel 2.6.24 - probably upgraded by now
Posts: 1,054

Original Poster
Rep: Reputation: 46
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any way in iptables to find ipaddress of a interface while firing iptable ru gopalgurus Linux - Networking 1 06-19-2006 06:40 AM
how to find ipaddress of the other system when we r chatting.. ramabrahmam Linux - Networking 1 04-29-2006 09:50 AM
Trying to find a WebDAV client guarriman Linux - Software 1 03-01-2006 03:02 PM
Find a bittorent client? hraposo Linux - Distributions 1 11-02-2004 02:31 PM


All times are GMT -5. The time now is 03:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration