in foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/net/NetUtils.java [107:128]
private static String tryGetHostAddressFromNetworkInterface(boolean isIpv6, InetAddress localhost) {
InetAddress result = null;
for (Entry<String, InetAddress> entry : allInterfaceAddresses.entrySet()) {
if (isIpv6 && entry.getKey().endsWith(IPV6_KEY)) {
result = entry.getValue();
if (entry.getKey().startsWith(PREFERRED_INTERFACE)) {
return result.getHostAddress();
}
} else if (!isIpv6 && entry.getKey().endsWith(IPV4_KEY)) {
result = entry.getValue();
if (entry.getKey().startsWith(PREFERRED_INTERFACE)) {
return result.getHostAddress();
}
}
}
if (result == null) {
return localhost.getHostAddress();
}
return result.getHostAddress();
}