Why the 127.0.1.1?

A

Amankwah

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?
 
G

Gordon Beaton

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

--
 
T

Tom Hawtin

Amankwah said:
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
 
A

Amankwah

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

Thanks!
it's worked!

Amankwah
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top