Class DnsClient
java.lang.Object
org.graylog2.lookup.adapters.dnslookup.DnsClient
-
Constructor Summary
ConstructorDescriptionDnsClient
(long queryTimeout) Creates a new DNS client with the given query timeout.DnsClient
(long queryTimeout, int resolverPoolSize, long resolverPoolRefreshSeconds) DnsClient
(long queryTimeout, long requestTimeout) Creates a new DNS client with the given query and request timeout. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
allIpAddressesValid
(String ipAddresses) getInverseAddressFormat
(String ipAddress) static boolean
isHostName
(String hostName) static boolean
isIp4Address
(String ipAddress) static boolean
isIp6Address
(String ipAddress) static void
parseReverseLookupDomain
(PtrDnsAnswer.Builder dnsAnswerBuilder, String hostname) Extract the domain name (without subdomain).resolveIPv4AddressForHostname
(String hostName, boolean includeIpVersion) resolveIPv6AddressForHostname
(String hostName, boolean includeIpVersion) reverseLookup
(String ipAddress) void
void
stop()
-
Constructor Details
-
DnsClient
public DnsClient(long queryTimeout) Creates a new DNS client with the given query timeout. The request timeout will be the query timeout plus theDEFAULT_REQUEST_TIMEOUT_INCREMENT
.- Parameters:
queryTimeout
- the query timeout- See Also:
-
DnsClient
public DnsClient(long queryTimeout, long requestTimeout) Creates a new DNS client with the given query and request timeout. The query timeout is the maximum time to wait for a DNS response from a DNS server. The request timeout is the maximum time to wait for the DNS request completion. The request timeout should always be higher than the query timeout. Background: The request timeout is used to avoid blocking a thread by waiting for the DNS resolve future to complete. This can happen when theDnsNameResolver
is closed, and the event loop is shut down while a resolver request is still running.- Parameters:
queryTimeout
- the query timeoutrequestTimeout
- the request timeout
-
DnsClient
public DnsClient(long queryTimeout, int resolverPoolSize, long resolverPoolRefreshSeconds)
-
-
Method Details
-
start
-
stop
public void stop() -
resolveIPv4AddressForHostname
public List<ADnsAnswer> resolveIPv4AddressForHostname(String hostName, boolean includeIpVersion) throws InterruptedException, ExecutionException, UnknownHostException -
resolveIPv6AddressForHostname
public List<ADnsAnswer> resolveIPv6AddressForHostname(String hostName, boolean includeIpVersion) throws InterruptedException, ExecutionException, UnknownHostException -
reverseLookup
-
parseReverseLookupDomain
Extract the domain name (without subdomain). The GuavaInternetDomainName
implementation provides a method to correctly handle this (and handles special cases for TLDs with multiple names. eg. for lb01.store.amazon.co.uk, only amazon.co.uk would be extracted). It uses https://publicsuffix.org behind the scenes.Some domains (eg. completely randomly defined PTR domains) are not considered to have a public suffix according to Guava. For those, the only option is to manually extract the domain with string operations. This should be a rare case.
-
txtLookup
public List<TxtDnsAnswer> txtLookup(String hostName) throws InterruptedException, ExecutionException -
getInverseAddressFormat
-
isHostName
-
isIp4Address
-
isIp6Address
-
allIpAddressesValid
- Parameters:
ipAddresses
- A comma-separated list of IP addresses- Returns:
- true if all comma-separated IP addresses are valid "8.8.4.4, 8.8.8.8" returns true "8.8.4.4, " returns true "8.8.4.4" returns true "8.8.4.4 8.8.8.8" returns false "8.8.4.4, google.com" returns false
-