Solved

Get Client's IP Address.

Posted on 2000-03-11
9
7,953 Views
Last Modified: 2011-08-18
Hi,
Is there a script that can get me the client's IP address.
And if that client is behind a proxy or firewall can I get both the client's internal IP address as well as his proxy's Ip address?
0
Comment
Question by:soso071898
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Expert Comment

by:kollegov
ID: 2609369
You can't detect user IP with Javascript when MIE used as browser.  
MIE always return 127.0.0.1
(:Bill's understanding of security :)
Meanwhile it possible to do with my VMaxIPCatcher Java Applet. It have JavaScript callback of setIP(ip) javascript function, so you can define this function and it will be called and IP will be passed into this function.. You would find applet at my site
http://come.to/vmax 
follow links in menu..                 ->applets->misc->VMaxIpCatcher

This applet work for NN3+, MIE4+
and return client IP even if client is behind firewall..Sorry, I don't know the way to get clien't firewall/proxy IP address...

Virtual_Max
0
 
LVL 1

Expert Comment

by:lambda
ID: 2611118

Using CGI you can get the client (proxy) IP from environment variable:

$ENV{'REMOTE_ADDR'};
0
 

Author Comment

by:soso071898
ID: 2614657
Thanks Kollegov but I need to use GetIpAddress function on the clients side (not in CGI) in my application which I am developing for a client. I need a way to make this by myself or use a free non-licensed code. Is your class free for commercial use? Also The code posted at your page is not working on my PC which is behind a proxy. I expected to get at least the local IP address.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 10

Accepted Solution

by:
kollegov earned 200 total points
ID: 2615993
Quite strange that it didn't work for you. Do you mean that when you accessed
my page at
http://www.geocities.com/virtual_max/vmaxipcatcher.html
you didn't got your IP address?
May be you wasn't patient enough? Sometimes geocities is too slow, and applet loading can be a bit slow..

Can you tell details of browser you use?

Actually, doesn't matter that you are behind proxy, it must work.

As for license terms :)...
Any of my applets are absolutely free with KEY  "Free Version", but free versions expose link back to my site. In addition this applet with "free version" do not perform javascript callback.

I can build version of VMaxIPcatcher which wouldn't have the last limitation.  You can e-mail me virtual_max@geocities.com and I'll e-mail you package.
0
 

Expert Comment

by:GlobalVillage
ID: 2859558
I'm entering into this kind of late, but will this do?

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
document.write("Your IP address is " + ip);
}
else {
document.write("IP Address only shown in Netscape with Java enabled!");
}
//  End -->
</script>
0
 

Expert Comment

by:GlobalVillage
ID: 2859573
But where are my manners.  You'll need IE code as well.

Try this one:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin

if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
alert("Your IP address is " + ip);
}
else {
if(navigator.javaEnabled() && (navigator.appName != "Microsoft Internet Explorer")) {
vartool=java.awt.Toolkit.getDefaultToolkit();
addr=java.net.InetAddress.getLocalHost();
host=addr.getHostName();
ip=addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);
   }
}
 
//  End -->
</script>



0
 
LVL 10

Expert Comment

by:kollegov
ID: 2862277
Global Village, before posting code
it's a good manner to test it yourself...

1. MIE do not allow to call classes from java packages directly..
2. Among 2  branches of your code
one for Navigator
and other NOT for explorer :-)

Where is explorer branch????

Soso, you need to run applet via http:// protocol to get IP. It wouldn't detect IP in case it was started from local file

0
 

Author Comment

by:soso071898
ID: 2941891
Comment accepted as answer
0
 

Author Comment

by:soso071898
ID: 2941892
Thanks for all of you.
Kollegov's applet is working fine
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 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