Use getFirstNonLoopbackAddress() from cloud commons
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import static org.springframework.cloud.consul.discovery.IpAddressUtils.getFirstNonLoopbackAddress;
|
||||
import static org.springframework.cloud.util.InetUtils.getFirstNonLoopbackAddress;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -43,27 +43,4 @@ public class IpAddressUtils {
|
||||
}
|
||||
return service.getNode();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static InetAddress getFirstNonLoopbackAddress() {
|
||||
try {
|
||||
for (Enumeration<NetworkInterface> enumNic = NetworkInterface.getNetworkInterfaces();
|
||||
enumNic.hasMoreElements(); ) {
|
||||
NetworkInterface ifc = enumNic.nextElement();
|
||||
if (ifc.isUp()) {
|
||||
for (Enumeration<InetAddress> enumAddr = ifc.getInetAddresses();
|
||||
enumAddr.hasMoreElements(); ) {
|
||||
InetAddress address = enumAddr.nextElement();
|
||||
if (address instanceof Inet4Address && !address.isLoopbackAddress()) {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
log.error("Cannot get host info", ex);
|
||||
}
|
||||
return InetAddress.getLocalHost();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user