Package de.measite.minidns
Class Client
- java.lang.Object
-
- de.measite.minidns.Client
-
public class Client extends java.lang.Object
A minimal DNS client for SRV/A/AAAA/NS and CNAME lookups, with IDN support. This circumvents the missing javax.naming package on android.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bufferSize
The buffer size for dns replies.protected DNSCache
cache
The internal DNS cache.private static java.util.logging.Logger
LOGGER
protected java.util.Random
random
The internal random class for sequence generation.protected int
timeout
DNS timeout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
findDNS()
Retrieve a list of currently configured DNS servers.protected java.lang.String[]
findDNSByExec()
Try to retrieve the list of dns server by executing getprop.protected java.lang.String[]
findDNSByReflection()
Try to retrieve the list of dns server by calling SystemProperties.int
getTimeout()
Retrieve the current dns query timeout, in milliseconds.DNSMessage
query(Question q)
Query the system DNS server for one entry.DNSMessage
query(Question q, java.lang.String host)
Query a specific server for one entry.DNSMessage
query(Question q, java.lang.String host, int port)
Query a specific server for one entry.DNSMessage
query(java.lang.String name, Record.TYPE type)
Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).DNSMessage
query(java.lang.String name, Record.TYPE type, Record.CLASS clazz)
Query the system nameservers for a single entry of any class.DNSMessage
query(java.lang.String name, Record.TYPE type, Record.CLASS clazz, java.lang.String host)
Query a nameserver for a single entry.DNSMessage
query(java.lang.String name, Record.TYPE type, Record.CLASS clazz, java.lang.String host, int port)
Query a nameserver for a single entry.void
setTimeout(int timeout)
Change the dns query timeout for all future queries.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
random
protected java.util.Random random
The internal random class for sequence generation.
-
bufferSize
protected int bufferSize
The buffer size for dns replies.
-
timeout
protected int timeout
DNS timeout.
-
cache
protected DNSCache cache
The internal DNS cache.
-
-
Constructor Detail
-
Client
public Client(DNSCache cache)
Create a new DNS client with the given DNS cache.- Parameters:
cache
- The backend DNS cache.
-
Client
public Client(java.util.Map<Question,DNSMessage> cache)
-
Client
public Client()
Create a new DNS client without any caching.
-
-
Method Detail
-
getTimeout
public int getTimeout()
Retrieve the current dns query timeout, in milliseconds.- Returns:
- the current dns query timeout in milliseconds.
-
setTimeout
public void setTimeout(int timeout)
Change the dns query timeout for all future queries. The timeout must be specified in milliseconds.- Parameters:
timeout
- new dns query timeout in milliseconds.
-
query
public DNSMessage query(java.lang.String name, Record.TYPE type, Record.CLASS clazz, java.lang.String host, int port) throws java.io.IOException
Query a nameserver for a single entry.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).host
- The DNS server host.port
- The DNS server port.- Returns:
- The response (or null on timeout / failure).
- Throws:
java.io.IOException
- On IO Errors.
-
query
public DNSMessage query(java.lang.String name, Record.TYPE type, Record.CLASS clazz, java.lang.String host) throws java.io.IOException
Query a nameserver for a single entry.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).host
- The DNS server host.- Returns:
- The response (or null on timeout / failure).
- Throws:
java.io.IOException
- On IO Errors.
-
query
public DNSMessage query(java.lang.String name, Record.TYPE type, Record.CLASS clazz)
Query the system nameservers for a single entry of any class. This can be used to determine the name server version, if name is version.bind, type is TYPE.TXT and clazz is CLASS.CH.- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).- Returns:
- The response (or null on timeout/error).
-
query
public DNSMessage query(java.lang.String name, Record.TYPE type)
Query the system nameservers for a single entry of the class IN (which is used for MX, SRV, A, AAAA and most other RRs).- Parameters:
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).- Returns:
- The response (or null on timeout/error).
-
query
public DNSMessage query(Question q, java.lang.String host) throws java.io.IOException
Query a specific server for one entry.- Parameters:
q
- The question section of the DNS query.host
- The dns server host.- Returns:
- The response (or null on timeout/error).
- Throws:
java.io.IOException
- On IOErrors.
-
query
public DNSMessage query(Question q, java.lang.String host, int port) throws java.io.IOException
Query a specific server for one entry.- Parameters:
q
- The question section of the DNS query.host
- The dns server host.port
- the dns port.- Returns:
- The response (or null on timeout/error).
- Throws:
java.io.IOException
- On IOErrors.
-
query
public DNSMessage query(Question q)
Query the system DNS server for one entry.- Parameters:
q
- The question section of the DNS query.- Returns:
- The response (or null on timeout/error).
-
findDNS
public java.lang.String[] findDNS()
Retrieve a list of currently configured DNS servers.- Returns:
- The server array.
-
findDNSByExec
protected java.lang.String[] findDNSByExec()
Try to retrieve the list of dns server by executing getprop.- Returns:
- Array of servers, or null on failure.
-
findDNSByReflection
protected java.lang.String[] findDNSByReflection()
Try to retrieve the list of dns server by calling SystemProperties.- Returns:
- Array of servers, or null on failure.
-
-