Sunday, November 8, 2015

Java example using WhoisClient class

The WhoisClient class implements the client side of the Internet Whois Protocol defined in RFC 954. To query a host you create a WhoisClient instance, connect to the host, query the host, and finally disconnect from the host. If the whois service you want to query is on a non-standard port, connect to the host at that port.
org.apache.commons.net.whois.WhoisClient

Example:
package javawhoisclient;

import java.io.IOException;
import org.apache.commons.net.whois.WhoisClient;

/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaWhoisClient {

    public static void main(String[] args) {
        WhoisClient whois;

        whois = new WhoisClient();

        try {
            whois.connect(WhoisClient.DEFAULT_HOST);
            System.out.println(whois.query("=google.com"));
            whois.disconnect();
        } catch (IOException e) {
            System.err.println("Error I/O exception: " + e.getMessage());
            return;
        }
    }

}




To use WhoisClient class in your program, you have to include library commons-net-3.3 in your code, it can be download here: https://commons.apache.org/proper/commons-net/index.html

This video show how to download and add library commons-net-3.3 to NetBeans IDE.


Next:
query InterNIC server's whois without WhoisClient class.

No comments:

Post a Comment