/**
* Get host IP address
*
* @return IP Address
*/
private static InetAddress getAddress() {
try {
for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
NetworkInterface networkInterface = interfaces.nextElement();
if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
continue;
}
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
if (addresses.hasMoreElements()) {
return addresses.nextElement();
}
}
} catch (SocketException e) {
}
return null;
}
转载于:https://my.oschina.net/tinglanrmb32/blog/693614