java.net.InetAddress.getLocalHost() with 2 NIC cards

Hi,

I have 2 NIC cards in my Windows 2003 server machine.

The getLocalHost() is returning the IP address of the 2nd NIC card i.e. it is returning the IP address which is listed second when I do ipconfig in the Windows CLI.

It is returning the first IP address in all the other machines with Windows 2000 Prof OS.

java.net.InetAddress.getLocalHost();

Does anyone have any idea why is this inconsistent behavior with the getLocalHost() method?

[478 byte] By [b_a_sa] at [2007-10-3 11:13:20]
# 1
It should return whichever IP Address is resolved to using the hostname of the computer. It is completely irrelevant in which order the IP Addresses are listed during an ipconfig command. Ping your own hostname and check that the IP Address returned conforms to the IP Address pinged.
masijade.a at 2007-7-15 13:37:01 > top of Java-index,Core,Core APIs...
# 2
J2SE 1.5 includes NetworkInterface class that enumerates all local network adapters so you can work on different hardware.
watertownjordana at 2007-7-15 13:37:01 > top of Java-index,Core,Core APIs...
# 3

> It should return whichever IP Address is resolved to

> using the hostname of the computer. It is completely

> irrelevant in which order the IP Addresses are listed

> during an ipconfig command. Ping your own hostname

> and check that the IP Address returned conforms to

> the IP Address pinged.

Thanks. I tested it and found that it returns the same IP address as it does when we ping the hostname. That means the hostname is bind to the other NIC card.

But I'm surprised why the hostname is bound to the secondary NIC card ip address. Could this be an issue with OS hostname/ipaddress binding?

b_a_sa at 2007-7-15 13:37:01 > top of Java-index,Core,Core APIs...
# 4

No. It simply means that the network cable that provides your general access to the network is plugged into the second card. That's all.

Edit: At least if your hostname is associated with the IP Address that is publicly available. This is not always the case, but generally so.

Otherwise, your hostname simply refers to an IP Address that is only visible on a smaller, more private network, and the IP Address with which the machine is reached from the general network, is associated with a different name than that which the machine knows itself by.

masijade.a at 2007-7-15 13:37:01 > top of Java-index,Core,Core APIs...