whois.py March 1, 2008
Posted by cillian in Uncategorized.trackback
# 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
I was trying to do something with whois in python, your script helped me a lot, thanks.