views:

397

answers:

3

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.

+5  A: 

Hi there,

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
A: 

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
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
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
Your algorithm is wrong if the TLD use wildcards, which happens.
bortzmeyer
Which TLDs use wildcards?
Matthew
+2  A: 

There's a good Whois Java client here:

http://www.skytouch.com/soft/java/whois.html

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

// don't include the www        
Whois.main(new String[] {"skytouch.com"});
Jon
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!
Jon