public class ResolverApi
extends java.lang.Object
A simple exammple how to resolve the IPv4 address of a given domain:
ResolverResult<A> result = DnssecResolverApi.INSTANCE.resolve("verteiltesysteme.net", A.class);
if (!result.wasSuccessful()) {
RESPONSE_CODE responseCode = result.getResponseCode();
// Perform error handling.
…
return;
}
if (!result.isAuthenticData()) {
// Response was not secured with DNSSEC.
…
return;
}
Set<A> answers = result.getAnswers();
for (A a : answers) {
InetAddress inetAddress = a.getInetAddress();
// Do someting with the InetAddress, e.g. connect to.
…
}
MiniDNS also supports SRV resource records as first class citizens:
SrvResolverResult result = DnssecResolverApi.INSTANCE.resolveSrv(SrvType.xmpp_client, "example.org")
if (!result.wasSuccessful()) {
RESPONSE_CODE responseCode = result.getResponseCode();
// Perform error handling.
…
return;
}
if (!result.isAuthenticData()) {
// Response was not secured with DNSSEC.
…
return;
}
List<ResolvedSrvRecord> srvRecords = result.getSortedSrvResolvedAddresses();
// Loop over the domain names pointed by the SRV RR. MiniDNS will return the list
// correctly sorted by the priority and weight of the related SRV RR.
for (ResolvedSrvRecord srvRecord : srvRecord) {
// Loop over the Internet Address RRs resolved for the SRV RR. The order of
// the list depends on the prefered IP version setting of MiniDNS.
for (InternetAddressRR inetAddressRR : srvRecord.addresses) {
InetAddress inetAddress = inetAddressRR.getInetAddress();
int port = srvAddresses.port;
// Try to connect to inetAddress at port.
…
}
}
| Modifier and Type | Field and Description |
|---|---|
static ResolverApi |
INSTANCE |
| Constructor and Description |
|---|
ResolverApi(org.minidns.AbstractDnsClient dnsClient) |
| Modifier and Type | Method and Description |
|---|---|
org.minidns.AbstractDnsClient |
getClient() |
<D extends org.minidns.record.Data> |
resolve(org.minidns.dnsname.DnsName name,
java.lang.Class<D> type) |
<D extends org.minidns.record.Data> |
resolve(org.minidns.dnsmessage.Question question) |
<D extends org.minidns.record.Data> |
resolve(java.lang.String name,
java.lang.Class<D> type) |
SrvResolverResult |
resolveSrv(org.minidns.dnsname.DnsName name)
Resolve the
SRV resource record for the given name. |
SrvResolverResult |
resolveSrv(org.minidns.dnsname.DnsName service,
org.minidns.dnsname.DnsName proto,
org.minidns.dnsname.DnsName name) |
SrvResolverResult |
resolveSrv(SrvService service,
SrvProto proto,
org.minidns.dnsname.DnsName name) |
SrvResolverResult |
resolveSrv(SrvService service,
SrvProto proto,
java.lang.String name) |
SrvResolverResult |
resolveSrv(SrvType type,
org.minidns.dnsname.DnsName serviceName) |
SrvResolverResult |
resolveSrv(SrvType type,
java.lang.String serviceName) |
SrvResolverResult |
resolveSrv(java.lang.String name) |
ResolverResult<org.minidns.record.PTR> |
reverseLookup(java.lang.CharSequence inetAddressCs) |
ResolverResult<org.minidns.record.PTR> |
reverseLookup(java.net.Inet4Address inet4Address) |
ResolverResult<org.minidns.record.PTR> |
reverseLookup(java.net.Inet6Address inet6Address) |
ResolverResult<org.minidns.record.PTR> |
reverseLookup(java.net.InetAddress inetAddress) |
public static final ResolverApi INSTANCE
public final <D extends org.minidns.record.Data> ResolverResult<D> resolve(java.lang.String name, java.lang.Class<D> type) throws java.io.IOException
java.io.IOExceptionpublic final <D extends org.minidns.record.Data> ResolverResult<D> resolve(org.minidns.dnsname.DnsName name, java.lang.Class<D> type) throws java.io.IOException
java.io.IOExceptionpublic <D extends org.minidns.record.Data> ResolverResult<D> resolve(org.minidns.dnsmessage.Question question) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(SrvType type, java.lang.String serviceName) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(SrvType type, org.minidns.dnsname.DnsName serviceName) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(SrvService service, SrvProto proto, java.lang.String name) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(SrvService service, SrvProto proto, org.minidns.dnsname.DnsName name) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(org.minidns.dnsname.DnsName service, org.minidns.dnsname.DnsName proto, org.minidns.dnsname.DnsName name) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(java.lang.String name) throws java.io.IOException
java.io.IOExceptionpublic ResolverResult<org.minidns.record.PTR> reverseLookup(java.lang.CharSequence inetAddressCs) throws java.io.IOException
java.io.IOExceptionpublic ResolverResult<org.minidns.record.PTR> reverseLookup(java.net.InetAddress inetAddress) throws java.io.IOException
java.io.IOExceptionpublic ResolverResult<org.minidns.record.PTR> reverseLookup(java.net.Inet4Address inet4Address) throws java.io.IOException
java.io.IOExceptionpublic ResolverResult<org.minidns.record.PTR> reverseLookup(java.net.Inet6Address inet6Address) throws java.io.IOException
java.io.IOExceptionpublic SrvResolverResult resolveSrv(org.minidns.dnsname.DnsName name) throws java.io.IOException
SRV resource record for the given name. After ensuring that the resolution was successful
with ResolverResult.wasSuccessful() , and, if DNSSEC was used, that the results could be verified with
ResolverResult.isAuthenticData(), simply use SrvResolverResult.getSortedSrvResolvedAddresses() to
retrieve the resolved IP addresses.
The name of SRV records is "_[service]._[protocol].[serviceDomain]", for example "_xmpp-client._tcp.example.org".
name - the name to resolve.SrvResolverResult instance which can be used to retrieve the addresses.java.io.IOException - if an IO exception occurs.public final org.minidns.AbstractDnsClient getClient()