I used the InetAddress.getLocalHost() to get my IP address, buy i got
127.0.1.1?
How can i get my REAL ip address?
Gordon Beaton - 02 Jul 2007 15:13 GMT
> I used the InetAddress.getLocalHost() to get my IP address, buy i
> got 127.0.1.1? How can i get my REAL ip address?
That is one of your REAL ip adresses.
To get all of them (and choose one you like better) have a look at
java.net.NetworkInterface.getNetworkInterfaces().
/gordon
--
Tom Hawtin - 02 Jul 2007 15:22 GMT
> I used the InetAddress.getLocalHost() to get my IP address, buy i got
> 127.0.1.1?
> How can i get my REAL ip address?
Are you using a Debian-based distribution of Linux? IIRC, when recent
Debian releases are using DHCP, in order to give a consistently
functioning IP address it uses this address. I think this is necessary
for Gnome. Addresses in the 127 class-A network should never appear on
the (physical) wire.
The obvious solution is not to use dynamic IP assignment, but that is
perhaps not very helpful.
I tried getAllByName using my hostname, but only got the one result
(using Ubuntu 7.04).
From 1.6, it appears with a little experimentation that you can get
java.net.NetworkInterface to get the information.
for (
java.util.Enumeration<NetworkInterface> en =
NetworkInterface.getNetworkInterfaces();
en.hasMoreElements();
) {
NetworkInterface iface = en.nextElement();
System.err.println(iface.getInterfaceAddresses());
}
I have absolutely no idea why an interface introduced in 1.6 is still
using Enumeration.
Tom Hawtin
Amankwah - 03 Jul 2007 02:24 GMT
> > I used the InetAddress.getLocalHost() to get my IP address, buy i got
> > 127.0.1.1?
[quoted text clipped - 28 lines]
>
> Tom Hawtin
Thanks!
it's worked!
Amankwah
Roedy Green - 02 Jul 2007 17:04 GMT
>I used the InetAddress.getLocalHost() to get my IP address, buy i got
>127.0.1.1?
>How can i get my REAL ip address?
What you want is your "FACE IP".
See http://mindprod.com/jgloss/ip.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com