diff --git a/node/src/main/kotlin/net/corda/node/utilities/AddressUtils.kt b/node/src/main/kotlin/net/corda/node/utilities/AddressUtils.kt index 7fdb35c8a6..a65963289a 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/AddressUtils.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/AddressUtils.kt @@ -4,12 +4,16 @@ import java.net.InetAddress import java.net.NetworkInterface object AddressUtils { + private val REACHABLE_TIMEOUT_MS = 1000 + /** Returns the first public IP address found on any of the network interfaces, or `null` if none found. */ fun tryDetectPublicIP(): InetAddress? { for (int in NetworkInterface.getNetworkInterfaces()) { - if (int.name.startsWith("utun")) continue + if (int.isLoopback) continue + for (address in int.inetAddresses) { - if (isPublic(address)) return address + if (isPublic(address) && address.isReachable(REACHABLE_TIMEOUT_MS)) + return address } } return null