6

Is there a relatively simple way in Java to check if a domain is available or not?

I need a reliable method, so only checking if the connection can be made is not enough.

AJ.
  • 27,586
  • 18
  • 84
  • 94
Thizzer
  • 16,153
  • 28
  • 98
  • 139

4 Answers4

6

Domain availability depends on having a whois client. Here is a link to an implementation of a whois client in Java:

Java Whois Client

You'll need to parse the results - and depending on what whois server you use, you may (will) have varying formats that are returned. The best thing to do is to pay for a commercial whois/registration service such as OpenSRS. They have an extensive API which you can use as a registered reseller. Here are the API docs:

http://opensrs.com/resources/documentation/opensrs_xmlapi.pdf

HTH,

-aj

AJ.
  • 27,586
  • 18
  • 84
  • 94
4

There's a good Whois Java client here:

https://github.com/ethauvin/Whois

You can run it from the command line or interface with it directly:

// don't include the www        
Whois.main(new String[] {"skytouch.com"});
Philip
  • 697
  • 7
  • 20
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
  • It's under a GPL license so you can always modify it to do what you want, there's a Whois.java source file and a properties file to specify the Whois server, that's it! – Jonathan Holloway Feb 03 '10 at 23:10
1

Another solution is to use Apache Commons lib. Simplified example:

import org.apache.commons.net.whois.WhoisClient;

public String getWhois(String domainName){

    WhoisClient whois = new WhoisClient();

    whois.setConnectTimeout(10000);
    whois.setDefaultTimeout(10000);

    whois.connect("whois.verisign-grs.com", 43);

    String domainWhois = whois.query(domainName);

    whois.disconnect();

    return domainWhois;
}

Check if response equals "no match". Whois servers, timeout length and no availability response differ according to extension so you should have prepared additional collections for them.

Whois servers list can be found:

If you try to make your queries concurrent, you will definitely get whois response "You have reached configured rate limit." or explicit exception in a code so you should repeat queries after some sleep.

Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
0

Performing a DNS lookup on the domain is the easiest solution. All available domains will have no DNS record, and most registrars assign a default DNS entry upon registration.

WHOIS lookups will be your most reliable solution, particularly behind an ISP that spoofs their own server (with a "domain not found" page filled with ads) for any missing domain name.

Matthew
  • 2,024
  • 15
  • 19
  • 1
    No, using the DNS is a very bad idea. Many TLD (for instance, .FR) have domains which are registered but not published ("on hold" domains for .COM). – bortzmeyer Feb 08 '10 at 08:22
  • 1
    I disagree. Sometimes it is a good idea. If you want to know that a DOMAIN is NOT available, then doing a DNS lookup will tell you very quickly if it isn't available. If the DNS lookup fails, you then follow that by a much slower WHOIS lookup for the cases where the domain has no DNS records, but is registered. If performance is an issue, this is a good way to go. – jm. Feb 10 '10 at 22:59
  • Your algorithm is wrong if the TLD use wildcards, which happens. – bortzmeyer Feb 18 '10 at 09:01
  • @bortzmeyer Stéphane is right. . .COM did use wildcards in the past, albeit for a short period (the SiteFinder fiasco). The recursive DNS server you are using may be lying and introduce wildcards. The registry of .WS (among a couple of others, see Wikipedia) does wildcards. Etc. – Patrick Mevzek Jan 04 '18 at 21:20