|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.utils.dns.DNSClient
This is a client for the DNS name lookups.
The name lookups consists of creating a Question
instance and passing it
to the query(Question, InetAddress, int, boolean, Service)
method. Alternatively,
the query(String[], Service)
or main(String[])
method may be used,
too. The returned Message
object represents an answer from the remote DNS server.
The following example shows a simple use of the query method:
Question question = new Question("one.foo.bar", Types.A, class.IN); InetAddress server = InetAddress.getByName("ns.internic.net"); Message message = DNSClient.query(question, server, 60000, false, null); List answers = message.getAnswers(); System.out.println("Found " + answers.size() + " answers:"); for (Iterator it = answers.iterator(); it.hasNext(); ) System.out.println(it.next());
Field Summary | |
static int |
DEFAULT_LOOKUP_TIMEOUT
The default query timeout in seconds. |
Constructor Summary | |
DNSClient()
|
Method Summary | |
static void |
main(java.lang.String[] args)
Main static method for performing a DNS query. |
static Message |
query(Question question,
java.net.InetAddress server,
int timeout,
boolean stream,
Service logger)
Performs a DNS query. |
static Message |
query(java.lang.String[] args,
Service logger)
Peforms a DNS query command. |
static PTRResource |
reverseQuery(java.lang.String addr,
java.net.InetAddress server,
int timeout,
boolean stream,
Service logger)
Performs a reverse DNS query. |
static void |
setServer(java.net.InetAddress server)
Sets the default server for the name lookups. |
static void |
setTimeout(int timeout)
Sets the default name lookup timeout. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_LOOKUP_TIMEOUT
Value: 30
Constructor Detail |
public DNSClient()
Method Detail |
public static void setServer(java.net.InetAddress server)
The default server is set to "localhost" an may be changed via this method.
server
- the DNS server addresspublic static void setTimeout(int timeout)
The defaul value is set to DEFAULT_LOOKUP_TIMEOUT
and may be changed via this
method.
timeout
- the timeout in secondspublic static Message query(Question question, java.net.InetAddress server, int timeout, boolean stream, Service logger) throws java.io.IOException
A new TCP connection will be established for each query if the stream argument is true.
question
- the questionserver
- the DNS servertimeout
- the lookup timeout in millisecondsstream
- whether to use the TCP or UDP protocollogger
- the logging service or null
java.io.IOException
- if an error occuredpublic static PTRResource reverseQuery(java.lang.String addr, java.net.InetAddress server, int timeout, boolean stream, Service logger) throws java.io.IOException
This method converts a valid IP address to the full specified hostname represented
by a PTRResource
pointer.
A new TCP connection will be established for each query if the stream argument is true.
addr
- the IP addressserver
- the DNS servertimeout
- the lookup timeout in millisecondsstream
- whether to use the TCP or UDP protocollogger
- the logging service or null
java.io.IOException
- if an error occuredpublic static Message query(java.lang.String[] args, Service logger) throws java.io.IOException
The following arguments may be specified via the string array:
[-server hostname] [-type type] [-class class] [-timeout seconds] [-stream] hostname server - the domain name or IP address of the DNS server type - the resource type (A, CNAME, PTR, MX, ...) class - the protocol family (IN) timeout - the query timeout in seconds stream - whether to use TCP instead of the UDP protocol hostname - the query subject
This method parses the arguments, converts them to their corresponding Java
types and calls the query(Question, InetAddress, int, boolean, Service)
method.
args
- the query argumentslogger
- the loging service or null
java.io.IOException
- if an error occuredpublic static void main(java.lang.String[] args) throws java.io.IOException, ServiceException
It directly calls the query(String[], Service)
method. The output is redirected
to the standard system output.
args
- the query arguments
java.io.IOException
- if an error occured
ServiceException
- if an error occured
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |