Package google.registry.util
Class NetworkUtils
java.lang.Object
google.registry.util.NetworkUtils
Utilities for networking.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Returns the fully-qualified domain name of the local host in all lower case.static InetAddress
Returns the externally-facing IPv4 network address of the local host.static int
Returns random unused local port that can be used for TCP listening server.
-
Method Details
-
pickUnusedPort
public static int pickUnusedPort()Returns random unused local port that can be used for TCP listening server.- Throws:
RuntimeException
- if failed to find free port after 16 attempts
-
getCanonicalHostName
Returns the fully-qualified domain name of the local host in all lower case.- Throws:
RuntimeException
- to wrapUnknownHostException
if the local host could not be resolved into an address
-
getExternalAddressOfLocalSystem
Returns the externally-facing IPv4 network address of the local host.This function implements a workaround for an issue in
InetAddress.getLocalHost()
.Note: This code was pilfered from
com.google.net.base.LocalHost
which was never made open source.- Throws:
UnknownHostException
- if the local host could not be resolved into an address
-