This is a simple Java Example which uses Apache Commons Net library to pull all Whois data.
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.
You need below maven dependency in your pom.xml
file.
<dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.3</version> </dependency>
Here is a CrunchifyWhoisExample.java
file
package com.crunchify.tutorials; import java.io.IOException; import java.net.SocketException; import org.apache.commons.net.whois.WhoisClient; /** * @author Crunchify.com * */ public class CrunchifyWhoisExample { public static void main(String[] args) { CrunchifyWhoisExample obj = new CrunchifyWhoisExample(); System.out.println(obj.crunchifyWhois("crunchify.com")); System.out.println("\nTest Finished.."); } public String crunchifyWhois(String domainName) { StringBuilder whoisResult = new StringBuilder(""); WhoisClient crunchifyWhois = new WhoisClient(); try { // 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. crunchifyWhois.connect(WhoisClient.DEFAULT_HOST); String whoisData = crunchifyWhois.query("=" + domainName); whoisResult.append(whoisData); crunchifyWhois.disconnect(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return whoisResult.toString(); } }
Output:
Whois Server Version 2.0 Domain names in the .com and .net domains can now be registered with many different competing registrars. Go to http://www.internic.net for detailed information. Domain Name: CRUNCHIFY.COM Registrar: GO MONTENEGRO DOMAINS, LLC Whois Server: whois.gomontenegrodomains.com Referral URL: http://www.gomontenegrodomains.com Name Server: NS1.CRUNCHIFY.COM Name Server: NS2.CRUNCHIFY.COM Status: clientDeleteProhibited Status: clientRenewProhibited Status: clientTransferProhibited Status: clientUpdateProhibited Updated Date: 09-aug-2013 Creation Date: 06-apr-2013 Expiration Date: 06-apr-2020 >>> Last update of whois database: Fri, 04 Oct 2013 18:46:02 UTC <<< ..... ..... Test Finished..