Class NetworkUtils

java.lang.Object
google.registry.util.NetworkUtils

public final class NetworkUtils extends Object
Utilities for networking.
  • 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

      public static String getCanonicalHostName()
      Returns the fully-qualified domain name of the local host in all lower case.
      Throws:
      RuntimeException - to wrap UnknownHostException if the local host could not be resolved into an address
    • getExternalAddressOfLocalSystem

      public static InetAddress getExternalAddressOfLocalSystem() throws UnknownHostException
      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