mirror of
https://github.com/corda/corda.git
synced 2025-01-31 00:24:59 +00:00
Test if address is reachable before choosing
This commit is contained in:
parent
a01c466beb
commit
a2de90a6da
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user