Class DnsResolver

java.lang.Object
org.drasyl.util.DnsResolver

public final class DnsResolver extends Object
Helper class for resolving hostnames to IP addresses.
  • Method Details

    • resolveAll

      public static InetAddress[] resolveAll(String host) throws UnknownHostException
      Given the name of a host, returns an array of its IP addresses, based on the configured name service on the system.

      In contrast to InetAddress.getAllByName(String), this method takes care if resolved addresses are theoretically reachable from the local host. With the native JDK (especially OpenJDK) implementation we could observe that on IPv4-only systems hostnames are sometimes resolved to IPv6 addresses. This behavior is not deterministic and therefore makes the use of JDK-based resolution a gamble.

      When the program is started, it checks whether there is at least one IPv6-enabled network interface. If not, only resolved IPv4 addresses are returned by this method. It also takes into account which Internet Protocol version is preferred by Java. Addresses of the preferred version are located at the beginning of the returned list. If no version is preferred, IPv4 addresses are listed first.

      Parameters:
      host - name of host to resolve
      Throws:
      UnknownHostException - if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.
      See Also:
    • resolve

      public static InetAddress resolve(String host) throws UnknownHostException
      Returns the first address returned by resolveAll(String).
      Parameters:
      host - name of host to resolve
      Returns:
      first address returned by resolveAll(String)
      Throws:
      UnknownHostException - if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.