Вот код для определения предполагаемого имени локального хоста для работы с многосетевым ящиком:
/**
* Work out the first local host name by iterating the network interfaces
*
* @return
* @throws SocketException
*/
private String findFirstLocalHostName() throws SocketException {
Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress add = addresses.nextElement();
if (!add.isLoopbackAddress() && add.isSiteLocalAddress()) {
return add.getHostName();
}
}
}
throw new RuntimeException("Failed to determine local hostname");
}
Приводит ли вызов isSiteLocalAddress к ошибке? Я не могу найти никакой полезной информации об этом методе, но у меня такое ощущение, что он относится только к IP v 6 и устарел.