On 21 Aug 2004 07:41:23 GMT, Evertjan. <ex**************@interxnl.net>
wrote:
Lowell Kirsh wrote on 21 aug 2004 in comp.lang.javascript:
[snip]
var ip = new java.net.InetAddress.getLocalHost().toString();
alert("Your IP address is: " + ip.substring(ip.indexOf("/")+1))
What scriptlanguage/platform are you using ["new java.net"?]?
Surely not clientside javascript with DOM [=wisdom?] ?
It's Java (the networking package) being called from JavaScript. Opera and
IE don't seem to support that (if they do, a different syntax is required).
but this does not seem to work. It says the ip is 127.0.0.1. Strangely,
this piece of code used to work but all of a sudden it doesn't for some
unknown reason. Can anyone tell me what's wrong with the above code?
Whilst this would be more appropriate in a Java group, you're here now.
If you look at the description of the getLocalHost() method, you'll see:
If there is a security manager, its checkConnect method is called
with the local host name and -1 as its arguments to see if the
operation is allowed. If the operation is not allowed, an
InetAddress representing the loopback address is returned.
Java running under JavaScript will be using a security manager and, I
should imagine, a very restricted one at that. Whilst the code worked
running on my machine (using only Mozilla and Netscape, I might add), I
doubt that it will work from a remote host. In that case, as it states
above, you'll have the loopback address returned.
In other words: it a security thing that you can do nothing about.
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.