Class DnsResolver
-
Method Summary
Modifier and TypeMethodDescriptionstatic InetAddress
Returns the first address returned byresolveAll(String)
.static InetAddress[]
resolveAll
(String host) Given the name of a host, returns an array of its IP addresses, based on the configured name service on the system.
-
Method Details
-
resolveAll
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 thehost
could be found, or if a scope_id was specified for a global IPv6 address.- See Also:
-
resolve
Returns the first address returned byresolveAll(String)
.- Parameters:
host
- name of host to resolve- Returns:
- first address returned by
resolveAll(String)
- Throws:
UnknownHostException
- if no IP address for thehost
could be found, or if a scope_id was specified for a global IPv6 address.
-