This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?

-- 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]