IP Info Code Snippet problem

E

esrkq

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-details/browser-properties.html

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

Cheers
Paul.
 
K

Klaus Johannes Rusch

esrkq said:
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-details/browser-properties.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).
 
G

Grant Wagner

esrkq said:
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-details/browser-properties.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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,090
Messages
2,570,603
Members
47,223
Latest member
smithjens316

Latest Threads

Top