whois.py

# We’re looking for a name for the next high end free video editor
# and there are quite a lot of suggestions so far
# to test for available domain names I put this ditty together

# I believe a whois lookup doesn’t really tell you if a name
# has been taken but I guess it’s something

import commands
import sys
import time

if len(sys.argv) == 2:
    namelist = sys.argv[1]
else:
    print “please run it like this: python whois.py filename”

try:
    names = open(namelist, “r”).read().split(“\n”)[:-1]
    print “the following domain names may be available”
    for name in names:
        availabletlds = “”
        for tld in [“com”, “net”, “org”]:
            domainname = name+”.”+tld
            whoisresult = “”
            while not whoisresult or “fgets” in whoisresult or “LIMIT EXCEEDED” in whoisresult:
                whoisresult = commands.getoutput(“whois %s”% domainname)
                # whois gets upset if you query it too often
                if “fgets” in whoisresult or “LIMIT EXCEEDED” in whoisresult:
                    time.sleep(10)
                if “No match” in whoisresult or “NOT FOUND” in whoisresult:
                    availabletlds += ” “+tld
        print name + ” ” + availabletlds

except Exception, error:
    print error

Advertisements

1 thought on “whois.py”

  1. I was trying to do something with whois in python, your script helped me a lot, thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s