hosted by liquidweb

Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Perl or Java/Rails code to check for available domains

Forum Jump

Perl or Java/Rails code to check for available domains

Reply Post New Thread In Programming Discussion Subscription
Send news tip View All Posts Thread Tools Search this Thread Display Modes
Aspiring Evangelist
Join Date: Jul 2004
Posts: 375

Perl or Java/Rails code to check for available domains

I am looking for a script that can import a list of domains from a text file called domains.txt and check them one by one for availability. If a domain is available it will take the name and write it to a file called available.txt

This can be done using Perl (preferred) that I can run thru the command line or Rails (so I have heard).

I have read somewhere that you can use Perl or Rails to check for A records on the doamin. Most registered domains will have an A record so if it doesn't the script will consider this domain available. I can then take the names of available domains and conduct a more exact search for availability.

I would like to load in lists of domains that contain 5k to 15k of domains per list. It should be able to scan at a rate of 20-50 names per second.

Let me know if you know a script or if you can code it. PM me the price.

Sponsored Links
Web Hosting Master
Join Date: Nov 2001
Location: Vancouver
Posts: 2,416
I posted a Python script here sometime within the last 30 days or so that does almost exactly that. It was based off a script that I wrote for my own use that used a similar concept to find available domains. If there was no NS record (not A record) the domain was considered available.

The list of domains to check I created out of a large list of words and prefixes/suffixes in different combinations. I was getting 55 DNS results a second; I also cached the result of each run to a simple text format for persistence.

It wouldn't take much to run with the script I posted here:

... and make it do what you want.

“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”

Aspiring Evangelist
Join Date: Jul 2004
Posts: 375
I don't know Python, how much would you charge to customize it for me?

Sponsored Links
Join Date: Apr 2003
Location: Charleston, SC
Posts: 28

Here's a quick perl script that requires Net :: DNS (fairly common module).


# Domains Available
# Josh Skidmore <>
# 05 August 2007 | 11:40p EST

# Requirements
	use Net::DNS;
# Variables
	%VAR	=	(
					db => './domains.txt',
# Open file
	open (DB,$VAR{'db'});
	my (@domains) = <DB>;
	close (DB);

# Test domains
	foreach my $domain (@domains)
			my ($available) = &check_domain(domain => $domain);
			if ($available)
					print "$domain is available.<br />\n";
					print "$domain is NOT available<br />\n";
sub check_domain {
	# Test domain for existance
	# Josh Skidmore <>
	# 05 August 2007 | 11:42p EST
	# Variables
		my (%DATA) = @_ ;
		my ($available) = 0;

	# Start Net::DNS
		my $res = Net::DNS::Resolver->new;

		my ($domain) = $res->search($DATA{'domain'});
		if ($domain)
				($available) = 1;
	# Output
		return ($available);

__________________ - Find out information about any server, IP, or hostname

Web Hosting Master
Join Date: Aug 2005
Location: UK
Posts: 654
The fact that the domain name doesn't resolve does not mean it's available.

You should use a script that checks with a registrar. I use the enom API to check domain name availability, but all the larger resellers have these too.

Join Date: Apr 2006
Posts: 13
I would suggest Perl. And use some 3rd-party whois service.

Web Hosting Master
Join Date: Nov 2001
Location: Vancouver
Posts: 2,416
Originally Posted by sibsoft View Post
I would suggest Perl.
Why? Does it matter which language such a utility is written in?

“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”

Web Hosting Master
Join Date: Nov 2001
Location: Vancouver
Posts: 2,416
% ./ 
Domains to process: 566
Available domains written to file: 420
Run time: 1.32230615616
I decided that 25 - 50 results per second was too slow so I incorporated the example given into a threaded version which follows in this post. Depending on the state of your name server's cache, between 5 and 10 workers will probably do the job but regardless, its processing over 400 domains per second on a somewhat old desktop of mine. That ought to be fast enough.

Taking the example code of mine that I linked to earlier, you can see that the core code for checking the domains is only 3 lines of name server checking code plus a few lines here and there to read candidates from a test file and then write them back. Writing the python code to do the actual work took all of a few minutes. Adding in option parsing and threading took a little more time, mostly because I don't write threaded code very often. But still measured in minutes, not hours.

No charge.

In order to run this code you'll need python installed of course, plus download and install py-dns from Installing most python packages is dirt simple - usually involves no more than:

python install
Have at it.

(used PHP hilighter just to make this more readable on-line; it is Python of course)

PHP Code:
#!/usr/bin/env python

A multi-threaded DNS query solution, originally developed to check a
large list of candidate domain names -- if no NS is present, the candidate
likely does not have a domain registration.

(C) mwatkins, a user. Use for any purpose you like provided
attribution is provided.
# install PyDNS:
# FreeBSD: /usr/ports/dns/py-dns

import DNS
import threading
import time
import Queue
from optparse import OptionParser



def has_ns 
"""(domain:string) -> boolean
query DNS.Request(domainqtype="NS").req()
status query.header['status']
    return (

def get_domains_from_file(path):
"""(path:string) -> [string]

    Returns domains from a text file as a list of strings.
return [domain.strip() for domain in open(path).readlines()


def __init__(selfwork_queueresult_queue):
self.__queue work_queue
.__result result_queue

def run(self):
domain self.__queue.get()
domain is None:

def process_domains(domains):
"""(domains:sequence) -> ([string], [string])

    Processes a sequence of domain strings and returns two lists
    containing those that are potentially available for registration,
    and those which have name servers defined and are therefore unavailable.

    A final check for availability against a registrar whois API is recommended.
work Queue.Queue()
result Queue.Queue()
domain in domains:
# add work terminators
for i in range(WORKERS):

workers = [Worker(workresult) for i in range(WORKERS)]
worker in workers:

# wait for workers to complete
for w in workers:

available = []
unavailable = []
not result.empty():
domainstatus result.get(0)
status == 'NXDOMAIN':


def run_domain_checker_main

parser.set_description('Checks domain names for available name servers. '
        'Domain names with no name servers defined are potentially available '
        'for registration. A final check for availability against a registrar '
        'whois API is recommended.'
'-f''--inputfile'dest='input_file', default='domains.txt',
help='A file containing one domain name per line ')
'-o''--outputfile'dest='output_file', default='available.txt',
help=('A file to contain the candidate domains which may '
              'be available. Note: This file is overwritten on every run.'
'-s''--server'dest='dns_server', default=None,
help='Force use of a specific name server, overriding /etc/resolve.conf.')
'-t''--threads'dest='workers', default=10type=int,
help='Number of worker threads')
'-c''--cache'action="store_true"dest='use_cache', default=False,
help=('Use contents of <outputfile>, if it exists, as a cache. '
              'In other words, do not requery domains that have been found '
              'to be available. Newly found "available" domains will be '
              'added to the cache in <outputfile>.'

optionsargs parser.parse_args()
domains get_domains_from_file(options.input_file)
cached_domains = []
WORKERS options.workers
if options.dns_server:
DNS.defaults['server'] = [options.dns_server,]
cached_domains get_domains_from_file(options.output_file)
except IOErrore:
"INFO: Skipping cache"e
# we don't want to check those that already are in the output file
domains = [domain for domain in domains if domain not in
start time.time()
"Domains to process:"len(domains)
availunavail process_domains(domains)
fout open(options.output_file'w')
# we'll add cached_domains back to the output ([] if the option wasn't specified)
result sorted(avail cached_domains)
fout.writelines(['%s\n' domain for domain in result])
"Available domains written to file:"len(result)
"Run time:"time.time() - start

if __name__ == '__main__':

“Even those who arrange and design shrubberies are under
considerable economic stress at this period in history.”


Related posts from
Title Type Date Posted
Web Hosting Sales and Promos Roundup - December 5, 2014 Web Hosting News 2014-12-05 17:05:05
Web Hosting Sales and Promos Roundup - Cyber Monday 2014 Web Hosting News 2014-12-01 15:24:42
Web Hosting Sales and Promos Roundup - September 26, 2014 Web Hosting News 2014-09-26 15:37:14
Web Hosting Sales and Promos Roundup – August 2, 2013 Web Hosting News 2014-05-23 15:42:54
Cloud Platform Heroku Offers Free Ruby on Rails Training for Developers Web Hosting News 2013-04-12 14:41:30

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Log in with your username and password

Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Web Hosting News:
WHT Membership
WHT Membership



Welcome to

Create your username to jump into the discussion! is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.

(4 digit year)

Already a member?