This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
java.net.InetAddress
- From: Erik Poupaert <erik dot poupaert at chello dot be>
- To: java at gcc dot gnu dot org
- Date: Fri, 20 Jun 2003 23:55:17 +0000
- Subject: java.net.InetAddress
Hi
When I execute 'ifconfig' on my machine, I get the following output:
eth0 Link encap:Ethernet HWaddr 00:0B:CD:54:AE:61
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
...
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
...
On Windows, I get something similar with 'ipconfig'.
What I'm actually interested in, is the address "192.168.0.2"; the one
assigned to my machine by dhcpcd.
Regardless of what I try, however, java.net.InetAddress will never
return this address. It will always return the (absolutely useless)
loopback address "127.0.0.1":
String localHost=InetAddress.getLocalHost().getHostName();
System.out.println("local ip: " +
InetAddress.getLocalHost().getHostAddress());
System.out.println("localhost: " + localHost);
System.out.println("getByName:" +
InetAddress.getByName(localHost).getHostAddress());
InetAddress[] addresses=InetAddress.getAllByName(localHost);
System.out.println("address count: " + addresses.length);
for(int i=0;i<addresses.length;i++)
{
String ip=addresses[i].getHostAddress();
System.out.println("ip:" + ip);
}
Does anybody know, how I can get hold of the dhcp-assigned or statically
assigned address?
--