This should all be quite self explanatory. I can't remember why I went ahead and implemented this in Java. I think I was just rusty and wanted some practice. What follows is an implementation of the WHOIS protocol used to get information about a record name (in this case specifically domain name records). The nature of the information is contact information, ownership rights, etc.
The full source code and documentation can be downloaded here. This includes the source package and documentation. Depends only on Java core packages (java.io
, java.net
, and java.util
).
Let's start with the whois server pool (WhoisServerPool.java
). This is a static map of top level domain names to the whois server that is responsible for maintaining information on domains with that top level domain name.
The next class of note is the resolvers (ServerResolver.java
, ResolveDefault.java
, ResolveCRSNIC.java
, ResolveAfilias.java
, ResolvePIR.java
, ResolveURL.java
). Their job is to process a query in more detail. Some whois servers don't just give you the information. Sometimes you need to search around for it and that is the job of the resolvers. Each WhoisServer
uses one type of resolver.
A query object (WhoisQuery.java
) is packed with the requested query such as it's name. This is the main object a developer needs to use to issue a query. Once the object is initialised all you need to do is fetch it's response. The getResponse method returns a WhoisResponse with information on the query.
A whois response (WhoisResponse.java
) contains the query name and the reply.
Essentially that's it. It can be easily used as an API for reading developers to access the whois system if they have need to or a user can use the JavaWhois
application to query the whois server on the command line by executing and giving a list of domain names to query as arguments.
Example of using this code as a developer.
package org.neverfear.whois.examples; import org.neverfear.whois.WhoisQuery; import org.neverfear.whois.WhoisResponse; public class ExampleQuery { public static void main(String [] args) throws Exception { WhoisQuery query = new WhoisQuery("neverfear.org"); WhoisResponse response = query.getResponse(); System.out.println(response.getData()); } }
Example of using this code to access custom whois servers.
package org.neverfear.whois.examples; import org.neverfear.whois.ResolveDefault; import org.neverfear.whois.WhoisResponse; import org.neverfear.whois.WhoisServer; public class CustomServer { public static void main(String[] args) throws Exception { // Construct a whois server to use the default resolver and query the whois.neverfear.org. WhoisServer server = new WhoisServer(new ResolveDefault("whois.neverfear.org")); // Query this server for the record neverfear.org. WhoisResponse response = server.query("neverfear.org"); // Print the response. System.out.println(response.getData()); } }