Class Dns
- All Implemented Interfaces:
AutoCloseable
Configure DNS resolution and query DNS records directly from Chilkat.
Chilkat.Dns is a focused class for DNS configuration and DNS
record querying. It allows applications to control the nameservers used by
Chilkat, query common DNS record types into JSON, configure DNS-over-TLS
preference, set DNS query timeouts, and obtain useful diagnostics through
LastErrorText.
DNS record queries
Query common DNS record types and receive structured JSON results that are easy to inspect or pass to other application logic.
Nameserver control
Configure the nameservers Chilkat uses instead of relying only on the operating system's default DNS configuration.
DNS-over-TLS preference
Prefer DNS-over-TLS when appropriate for applications that need encrypted DNS lookups.
Timeout settings
Control how long DNS queries may wait before failing, which is useful for responsive applications and troubleshooting.
Application-wide behavior
Nameserver settings affect DNS resolution across Chilkat classes, not
only the current Dns object.
Diagnostics
Use LastErrorText to troubleshoot DNS configuration,
lookup failures, timeout problems, or nameserver connectivity issues.
Common pattern:
Use Dns either to perform direct DNS lookups, or to configure
the DNS behavior used by Chilkat as a whole. Because nameserver changes can
affect DNS resolution across Chilkat classes, treat them as application-wide
configuration rather than object-local state.
For an extended overview, see Dns Class Overview.
</section>
Event-capable: long-running methods report progress through a ProgressListener installed
with setProgressListener(ProgressListener), onAbortCheck(BooleanSupplier),
onPercentDone(IntPredicate) or onProgressInfo(BiConsumer).
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the default (auto-assigned) nameservers to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups.voidaddNameserver(String ipAddr, boolean supportsTls)Adds a new nameserver to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups.intThe interval in milliseconds between eachevent callback, which enables an application to abort certain method calls before they complete.AbortCheckintThe maxiumum number of milliseconds to wait for the answer to a DNS query.getNameserver(int index)Returns the IP address of the Nth nameserver currently used by Chilkat for DNS queries and domain to IP address lookups.intThe number of nameservers currently being used by Chilkat for DNS queries in all objects/classes, such as for HTTP, Email, FTP, SSH, etc.Returns the installed listener, ornull.intSpecifies the TLS preference.This is a catch-all property to be used for uncommon needs.voidonAbortCheck(BooleanSupplier callback)Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it.voidonPercentDone(IntPredicate callback)Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it.voidonProgressInfo(BiConsumer<String,String> callback)Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds.booleanquery(String recordType, String domain, JsonObject answer)Performs an DNS query fordomainand returns the answer inanswer.voidRemoves all nameservers from the collection of nameservers used by Chilkat.voidremoveNameserver(String ipAddr)Removes a nameserver from the collection of nameservers used by Chilkat.voidsetHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().voidsetMaxWaitMs(int value)Sets theMaxWaitMsproperty; seegetMaxWaitMs().voidsetProgressListener(ProgressListener listener)Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.voidsetTlsPref(int value)Sets theTlsPrefproperty; seegetTlsPref().voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Dns
public Dns()Creates a newDnsobject.
-
-
Method Details
-
getHeartbeatMs
public int getHeartbeatMs()The interval in milliseconds between eachevent callback, which enables an application to abort certain method calls before they complete. By default, HeartbeatMs is set toAbortCheck0, meaning no AbortCheck event callbacks will trigger.- Returns:
- the value of the
HeartbeatMsproperty
-
setHeartbeatMs
public void setHeartbeatMs(int value)Sets theHeartbeatMsproperty; seegetHeartbeatMs().- Parameters:
value- the new value
-
getMaxWaitMs
public int getMaxWaitMs()The maxiumum number of milliseconds to wait for the answer to a DNS query. A value of 0 is to wait indefinitely (no timeout). It's not a good idea to specify 0 (infinite timeout) or a value less than 1000 (1 second). The default value is 10000 milliseconds.- Returns:
- the value of the
MaxWaitMsproperty
-
setMaxWaitMs
public void setMaxWaitMs(int value)Sets theMaxWaitMsproperty; seegetMaxWaitMs().- Parameters:
value- the new value
-
getNumNameservers
public int getNumNameservers()The number of nameservers currently being used by Chilkat for DNS queries in all objects/classes, such as for HTTP, Email, FTP, SSH, etc.- Returns:
- the value of the
NumNameserversproperty (read-only)
-
getTlsPref
public int getTlsPref()Specifies the TLS preference. Possible values are:- 0 = No TLS
- 1 = Prefer TLS if possible.
- 2 = Require TLS
The default value is 0. If TLS is preferred then DNS nameservers with TLS capability will be tried first. If none succeed, then UDP/TCP will be tried. If TLS is required, then only TLS capable nameservers will be tried and all DNS queries will use TLS.
Note: To use TLS, your application needs to first specify nameservers by calling AddNameserver once per nameserver with the supportsTls argument set to
true.- Returns:
- the value of the
TlsPrefproperty
-
setTlsPref
public void setTlsPref(int value)Sets theTlsPrefproperty; seegetTlsPref().- Parameters:
value- the new value
-
getUncommonOptions
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
addDefaultNameservers
public void addDefaultNameservers()Adds the default (auto-assigned) nameservers to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups. -
addNameserver
Adds a new nameserver to the collection of nameservers used by Chilkat for DNS queries and domain to IP address lookups. TheipAddrspecifies the IPv4 address of the nameserver. ThesupportsTlsindicates if the namserver supports DoT (DNS over TLS. DoT uses port 853 for encrypted DNS communication.) If the TlsPreference property is set to 1 or 2, then Chilkat will use TLS nameservers.- Parameters:
ipAddr- theipAddrargument (notnull)supportsTls- thesupportsTlsargument
-
getNameserver
Returns the IP address of the Nth nameserver currently used by Chilkat for DNS queries and domain to IP address lookups. Theindexspecifies the index of the nameserver. The 1st nameserver is atindex0.- Parameters:
index- theindexargument- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
query
Performs an DNS query fordomainand returns the answer inanswer. The type of DNS query is specified inrecordTypeand can be A, AAAA, ALIAS, CAA, MX, NS, SOA, TXT. Additional record types can be added as needed.- Parameters:
recordType- therecordTypeargument (notnull)domain- thedomainargument (notnull)answer- theanswerargument (notnull)- Returns:
- the result; this method never throws
ChilkatException
-
removeAllNameservers
public void removeAllNameservers()Removes all nameservers from the collection of nameservers used by Chilkat. An application can call this method to reset to 0 nameservers before adding new nameservers. If a DNS domain to IP address resolution is needed by Chilkat, then the auto-assigned nameserver IP addresses will be automaticaly restored. -
removeNameserver
Removes a nameserver from the collection of nameservers used by Chilkat. TheipAddris the IPv4 address of the nameserver to be removed.- Parameters:
ipAddr- theipAddrargument (notnull)
-
setProgressListener
Installs the listener that receives this object's progress events (abortCheck,percentDone,progressInfo) during its long-running methods; replaces any listener or lambda installed before;nullremoves it.- Parameters:
listener- the listener, ornull- Throws:
IllegalStateException- if called from inside one of this object's own callbacks
-
getProgressListener
Returns the installed listener, ornull.- Returns:
- the listener installed with
setProgressListener(ProgressListener)or one of theon...methods
-
onAbortCheck
Installs a listener whose only callback isabortCheck: called everyHeartbeatMsmilliseconds during a long-running method; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onPercentDone
Installs a listener whose only callback ispercentDone: called with the completion percentage (0..100) as a long-running method progresses; returntrueto abort it. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-
onProgressInfo
Installs a listener whose only callback isprogressInfo: called with a name/value pair of progress information as a long-running method proceeds. Replaces any listener installed before.- Parameters:
callback- the callback, ornullto remove the listener
-