By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

IP Info Code Snippet problem

P: n/a
Hi,

I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

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);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.

Cheers
Paul.

Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
esrkq wrote:
I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

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);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.


A server-side solution is generally less intrusive (starting the Java VM just
to determine the IP address may take a little while the first time your page is
loaded).

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2

P: n/a
esrkq wrote:
Hi,

I am looking at a way to return IP related information of a visitor loading
a web page and found the following snippet of code:

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);

at http://javascript.internet.com/user-...roperties.html

Has anyone got any experience of using these functions as I can't seem to
get them to work.

Cheers
Paul.


The code above only works in Netscape 4.x and Netscape 7.x (and other Gecko
based browsers assuming the user has installed the JRE), and only works if
client-side JavaScript and Java are enabled. If you're content targeting such a
small audience the the code above will work fine provided you make a couple of
modifications:

if (navigator.javaEnabled() &&
(navigator.appName != "Microsoft Internet Explorer")) {
var tool = java.awt.Toolkit.getDefaultToolkit();
var addr = java.net.InetAddress.getLocalHost();
var host = addr.getHostName();
var ip = addr.getHostAddress();
alert("Your host name is '" + host + "'\nYour IP address is " + ip);
}

But even on the platforms it works on, all it tells the user is what they can
already determine with winipcfg or ipconfig if they wished.

And if you're thinking of using the IP address information to somehow identify
users or restrict access, forget it. At work I connect to your web site from
165.x.x.x, but your code identifies me as being on the 10.x.x.x subnet. At
home, I connect from 24.x.x.x, but your code would tell me my IP address is
192.168.0.2 (or .5, depending on whether I was using my desktop or laptop).

Both 10.x.x.x and 192.168.x.x are reserved for private networks, and you're
likely to find *lots* of users connecting from computers with IP addresses in
those ranges.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.