Linux, , InetAddress.getLocalHost() loopback- ( 127/8, 127.0.0.1). , , /etc/hosts, , localhost.localdomain.
/, , IP-, (eth0 ), IPv4, loopback.
try {
NetworkInterface i = NetworkInterface.getByName("eth0");
if (i != null) {
Enumeration<InetAddress> iplist = i.getInetAddresses();
InetAddress addr = null;
while (iplist.hasMoreElements()) {
InetAddress ad = iplist.nextElement();
byte bs[] = ad.getAddress();
if (bs.length == 4 && bs[0] != 127) {
addr = ad;
break;
}
}
if (addr != null) {
System.out.println( addr.getCanonicalHostName() );
}
} catch (...) { ... }
, . .
, , @rafalmag
NetworkInterface.getByName( "eth0" ) NetworkInterface.getNetworkInterfaces()