TheTAZZone - Internet Chaos

Domain Checker Shell Script Part One

During the hunt for available domain names, I make frequent use of the whois utility from a Linux command line. I have never trusted web-based whois tools. You never know if your searches are being stored. Also, I haven’t found a web-based whois that is as flexible as a shell script. So, I’ve written a simple set of scripts to aid in the search for domains to register. I must warn you, it’s not pretty, but I hope you’ll find it useful.

NOTE: For reasons which I cannot fathom, the whois utility isn’t available by default on all *nix systems. On Debian, Ubuntu, and Mint, you can install it using the command
sudo apt-get install whois.

First, here is the code for wi.sh (so called because I wish I could find a gem):

#!/bin/sh
#
# This program is free software, licensed under the GNU GPL, >=2.0.
# This software comes with absolutely NO WARRANTY. Use at your own risk!
#
# wi.sh v0.1.0
# Author: Tim Kissane
#
# Check the whois record for the existence of a domain
# that I wi.sh I could buy. :)

term=Expiration
name=$1
tld=$2
timer=2

if [ "$tld" = "" ] # if no second arg, default to .com
then
tld=”.com”
fi

if [ "$tld" = ".ca" ]
then
term=Expiry
fi

if [ "$tld" = ".ly" ]
then
term=ACTIVE
fi

if [ "$tld" = ".co.uk" ]
then
term=Renewal
fi

if [ "$tld" = ".net.au" ] || [ "$tld" = ".com.au" ]
then
term=Registrant:
fi

echo Checking whois for $name$tld

if [ "$tld" = ".co.za" ]
then
whois $name$tld
else
whois $name$tld > /tmp/$name.tmp
grep $term /tmp/$name.tmp
rm /tmp/$name.tmp
fi

# Be nice to the whois server
sleep $timer

Put the attached script, wi.sh in your path and make it executable.
chmod 755 wi.sh

By default, the script uses .com as the TLD, to to only check for
available .coms, run this:

wi.sh isthisavailable

You will get something like this back:

Checking whois for isthisavailable.com
Expiration Date: 15-nov-2012

Since it has an expiration date, it is not available to register.

If you want to check a different tld, say .net, do this:

wi.sh isthisavailable .net

Notice the space between the name and the TLD.
The output of this (at this moment) is:
Checking whois for isthisavailable.net

No “Expiration” line, so it’s available.
This works for most, but not all TLDs. More code is needed for certain other TLDs.

Ok, you really want a bulk checker, something that can check hundreds or thousands of names.  That brings us to the next case, using a text file for input.

Put one name on each line of a file, without a TLD, like so:

sex
drugs
rock
and
roll
jimihendrixisonewiththeuniverse

Save it as sample.txt.

Running this:

for dn in `cat sample.txt`; do wi.sh $dn; done

This dumps one line at a time into the wi.sh script.  As it runs, it produces the following output:

Checking whois for sex.com
Expiration Date: 17-oct-2019
Checking whois for drugs.com
Expiration Date: 18-dec-2019
Checking whois for rock.com
Expiration Date: 17-sep-2019
Checking whois for and.com
Expiration Date: 16-dec-2010
Checking whois for roll.com
Expiration Date: 24-may-2011
Checking whois for jimihendrixisonewiththeuniverse.com

The first 5 are, unsurprisingly, not available.  The last name has no
“Expiration” line and is available to register. (go ahead, I don’t mind) :)

To do this with a different TLD, just add it into the command:

for dn in `cat sample.txt`; do wi.sh $dn .net; done

Now, for a really long list of names, this is a pain to watch the scrolling
output and will make your eyes glaze.  To save the ouput to a file, use
redirection:

for dn in `cat sample.txt`; do wi.sh $dn .net; done > output.txt

Or, if you want to watch the scrolling results and save to a file, use a pipe to tee:

for dn in `cat sample.txt`; do wi.sh $dn .net; done | tee output.txt

This is better, but who wants to pore through hundreds or thousands of lines
in output.txt looking for the available names?  Not me!

That’s when we use the next script, multilinegrep.pl, a short perl job
which should run on any *nix system with perl installed.

Save this code as ‘multilinegrep.pl':

#!/usr/bin/perl -w
#
# This program is free software, licensed under the GNU GPL, >=2.0.
# This software comes with absolutely NO WARRANTY. Use at your own risk!
#
# multilinegrep v0.1.0
# Author: Tim Kissane
#
# A small utility to find consecutive lines that begin
# with "Checking" in the output of wi.sh

$lastline=””;
$thisline=””;
$match=”0″;

while () {
$thisline=$_;
if (/^Checking/)
{
if ($match==”1″)
{
print substr ($lastline, 19);
}
$match=”1″;
} else {
$match=”0″;
}
$lastline=$thisline;
}

Again, place the script somewhere in your path and make it executable.
Then, run it like this:

multilinegrep.pl output.txt

This will find any available domains.  But wait!  It doesn’t work with this
sample ouput.txt! My perl script misses the last line. :(  Until I fix it, here’s the
workaround:

for dn in `cat sample.txt`; do wi.sh $dn; done |tee output.txt; echo Checking >> output.txt

The echo at the end adds a line begining with “Checking” at the end of the file. Now, it works. So,

multilinegrep.pl output.txt

produces:

jimihendrixisonewiththeuniverse.com

This can also be saved to a file,

multilinegrep.pl output.txt | tee available.txt

You can copy and paste the contents of available.txt into the form at valuate.com, estibot.com, godaddy.com or any where else you like. I will sometimes run several of these while sleeping, then I can register any found treasures in the morning.

In Part Two, I’ll add a few tips and tricks to perform even more powerful searches.
Peace,
Tim

( image courtesy of cosmosmagazine.com )

Do not use, republish, in whole or in part, without the consent of the Author. TheTAZZone policy is that Authors retain the rights to the work they submit and/or post…we do not sell, publish, transmit, or have the right to give permission for such…TheTAZZone merely retains the right to use, retain, and publish submitted work within it’s Network.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Advertise

If you'd like to advertise on The Mutt ( aka TheTAZZone.com ) feel free to contact us at: administration[at]thetazzone.com

TheTAZZone is a non-commercial entity. We do not sell any products or services ourselves. Our revenue comes from advertising and donations only.

We appreciate your support! Your advertising revenue ( or donations ) helps us to continue to upgrade, improve, and offset the costs of maintaining this site.

Donations can be made through the page ' Donate '.