Thizzer
Thizzer

Reputation: 16653

Check domain availability Java

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.

Upvotes: 7

Views: 7761

Answers (4)

Justinas Jakavonis
Justinas Jakavonis

Reputation: 8798

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.

Upvotes: 1

Jonathan Holloway
Jonathan Holloway

Reputation: 63652

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"});

Upvotes: 4

Matthew
Matthew

Reputation: 1875

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.

Upvotes: 0

AJ.
AJ.

Reputation: 28174

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

Upvotes: 6

Related Questions