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

How to get IP address in Javascript?

P: n/a
Rex
Hi all,

I need to get the IP address of client machines
from inside Mozilla, Netscape, and IE.

Many webpages say to use in Netscape 4+
the expression

var ip = java.net.getLocalhost.getIpAddress()

This for me always returns 127.0.0.1.

Is this a bug or should I get trying to retrieve
an array of addresses and then scan that?

Thanks.

Jun 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Rex wrote on 30 jun 2006 in comp.lang.javascript:
Hi all,

I need to get the IP address of client machines
from inside Mozilla, Netscape, and IE.

Many webpages say to use in Netscape 4+
the expression

var ip = java.net.getLocalhost.getIpAddress()
That is java, not javascript
This for me always returns 127.0.0.1.
. and indeed that is usually the ip of the localhost.
Is this a bug or should I get trying to retrieve
an array of addresses and then scan that?


The client IP adress is only available to the server
and to serverside code, I think,
and not to the client and it's code.

So using serverside j[ava]script under ASP it is simple:

<%
response.write(request.servervariables("remote_add r"));
%>

But then, the IP address is sometimes/usually not the machine address,
but the nat-router or the proxy address.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 30 '06 #2

P: n/a
var ip = java.net.getLocalhost.getIpAddress()

This may do the trick in Java :-

String rhost = getDocumentBase().getHost();
Int rport = getDocumentBase().getPort();

String lhost = (new Socket(rhost,
rport)).getLocalAddress().getHostName();
String laddr = (new Socket(rhost,
rport)).getLocalAddress().getHostAddress();

Curtasy of some MetaSploit code.

Aaron
Jul 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.