Domain Availability

If you are trying to find your next best domain, may it be for your company branding or for your domain porfolio investing, the following script may help. The script was tested with python3 and the only needed dependency, besides python3 itself, is the python-whois library.

The library can be installed through pip with the following command:

pip3 install python-whois

The script iterates through all the domains with 3 letters, from aaa.com to zzz.com and logs the domain without any registrar, which in turn may be available for acquisition. It may also be changed to search for dictionary words, another domain instead of .com, search 4 letters instead of 3, etc.

"The domain market is a very competitive space, working on a first come-first served, where the number of available domains with premium characteristics is limited and is disputed with the entire world. It shares a lot of similarities with the land market, but instead of a nearby city or a great view, you have premium branding or more visibility."

This python scripts creates 3 files in the same directory it is being executed in. Creates a log file, which the logging level can be changed from INFO to DEBUG, if any errors are being found. Creates a second lock file, if the script is interrupted in any way or stopped, so it doesn't start all the way from the beggining of the domain check, example aaa.com would be the most checked domain and so on. Finally it creates the last file for easier bulk domain name check, which is a CSV with all domains missing registrar, which may therefore be available to be bought.
The script is best executed as a background process and you can easily monitor it by tailing the domains.log file.

NOTE: The lock file might need to be deleted if changing between the functions 'threeLetterSearch', 'fourLetterSearch' or 'wordSearch'.

import csv
import logging
import os
import whois

from english_words import english_words_lower_alpha_set
from string import ascii_lowercase

TLD='.com'
CSV_PATH='{}/domains.csv'.format(os.path.dirname(__file__))
LOG_PATH='{}/domains.log'.format(os.path.dirname(__file__))
LOCK_PATH='{}/.domains'.format(os.path.dirname(__file__))

logging.basicConfig(filename=LOG_PATH, encoding='utf-8', level=logging.INFO,
  format='%(asctime)s %(levelname)s %(message)s')

def _check(dom, domain):
  try:
    domain.registrar
  except AttributeError:
    with open(CSV_PATH, 'a') as domainCSV:
      writer = csv.writer(domainCSV)
      writer.writerow([dom])

def _lookup(dom):
  if previous_dom and min(dom,previous_dom) == dom:
    logging.debug('Skipping {}'.format(dom))
    return
  logging.debug('Looking up {}'.format(dom))
  try:
   domain = whois.query(dom)
  except (TypeError,whois.exceptions.FailedParsingWhoisOutput,
    whois.exceptions.UnknownDateFormat) as error:
    logging.debug("Failed with error: {}".format(error))
    return
  except (Exception,KeyboardInterrupt):
    _exit(dom)
  _check(dom, domain)

def _lock():
  try:
    with open(LOCK_PATH, 'r') as domainLock:
      return domainLock.read()
  except FileNotFoundError:
    return None

def _exit(dom):
  with open(LOCK_PATH, 'w') as domainLock:
    domainLock.write(dom)
  logging.info('Finished')
  exit()

def threeLetterSearch():
  for a in ascii_lowercase:
    for b in ascii_lowercase: 
      for c in ascii_lowercase:
        _lookup('{}{}{}{}'.format(a,b,c,TLD))

def fourLetterSearch():
  for a in ascii_lowercase:
    for b in ascii_lowercase: 
      for c in ascii_lowercase:
        for d in ascii_lowercase:
          _lookup('{}{}{}{}{}'.format(a,b,c,d,TLD))

def wordSearch():
  for a in english_words_lower_alpha_set:
    _lookup('{}{}'.format(a,TLD))

previous_dom = _lock()
logging.info('Started')
threeLetterSearch()
#fourLetterSearch()
#WordSearch()
logging.info('Finished')

To run the script simply execute the following line in the terminal:

python3 /path/to/created_script.py