How to Find 3, 4, or 5 Letter Domains by Auto Search (Complete Code)

Finding a short, memorable domain name feels like striking gold these days. Most of the good ones are long gone. But what if you could put a tireless robot to work, checking thousands of possibilities for you while you sleep?

That’s exactly what we’re going to do.

This isn’t just about finding a domain; it’s about taking control of the search. Forget endlessly typing into GoDaddy’s search bar. We’re going to build a powerful, automated domain-finding script using Python. It will systematically check every single 3, 4, or even 5-letter domain you can think of, across any domain extension (.com, .org, .io, etc.), and give you a neat list of what’s available.

This is a deep dive. We’ll go through every step, from setting up your computer to understanding every line of code. By the end, you’ll not only have a powerful tool but also a much better understanding of how a little bit of code can solve a very real-world problem.

Let’s get started. πŸš€

The Grand Plan: How Our Domain Finder Will Work

Before we write a single line of code, let’s map out our strategy. Our script will be smart and efficient, following a clear, logical process:

  1. Generate Every Possibility: The script will start by creating a master list of all the domain names we want to check. If we’re looking for 3-letter .com domains, it will generate everything from aaa.com, aab.com, all the way to zzz.com.
  2. The First Pass (Direct WHOIS): For each generated domain, our script will perform a direct WHOIS query. Think of this as asking the internet’s official address book, “Hey, is anyone living at this address?” This method is fast, free, and our first line of attack. If the address book says “no entry found,” we’ve likely found an available domain!
  3. The Backup Plan (API Fallback): Sometimes, the direct WHOIS servers are busy, give a weird response, or just time out. To avoid missing a gem, our script needs a reliable backup. If the direct check fails, it will automatically query a professional service called WhoAPI. This is a more robust, commercial-grade check that gives us a definitive “yes” or “no.”
  4. Be a Good Internet Citizen: We can’t just hammer the servers with thousands of requests per second. That’s a quick way to get our IP address blocked. Our script will have a built-in delay (e.g., 2 seconds) between each check. It makes the process slower, but it’s respectful and ensures our script can run to completion.
  5. Log Everything: The script will neatly sort the results into three text files:
    • available_domains.txt: The treasure chest! Every available domain it finds goes in here.
    • taken_domains.txt: A list of all the domains that are already registered.
    • error_domains.txt: Any domains that couldn’t be checked for some reason.

This layered approach makes our tool robust. It’s fast when it can be, but reliable when it needs to be.

πŸ› οΈ Step 1: Setting Up Your Digital Workshop

python script

First, we need to get your computer ready. This involves installing Python and setting up a clean, isolated workspace called a “virtual environment.” This is crucial because it keeps the tools for this project separate from anything else on your system, preventing conflicts.

Follow the instructions for your operating system.

For Windows Users

  1. Check for Python: Open the Command Prompt (press Win + R, type cmd, and hit Enter) and type: python –version. If you see a version number (like Python 3.10.5), you’re good. If you get an error, you need to install it.
  2. Install Python: Go to the official python.org website and download the latest version. During installation, make sure to check the box that says “Add Python to PATH.” This is a critical step!
  3. Create Your Project Folder: Create a new folder where you’ll store the script. For example, C:\Users\YourUser\Desktop\DomainFinder.
  4. Set Up the Virtual Environment:
    • Open Command Prompt and navigate to your new folder:
cd C:\Users\YourUser\Desktop\DomainFinder
  • Now, create the virtual environment. We’ll call it
python -m venv venv
  • You’ll see a new venv folder appear. To activate it, run:
.\venv\Scripts\activate
  • Your command prompt line should now start with (venv). This means you’re in the isolated environment!
  • Install Required Tools: With your virtual environment active, install the necessary Python libraries:
pip install python-whois requests tqdm

For macOS Users

  • Install Homebrew (If you don’t have it): Homebrew is the best way to install software on a Mac. Open the Terminal app and paste this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Install Python: macOS comes with an older version of Python. It’s best to install the latest one via Homebrew:
brew install python
  • Create Your Project Folder: Open Terminal, and let’s create a folder on your Desktop:
cd ~/Desktop
mkdir DomainFinder
cd DomainFinder
  • Set Up the Virtual Environment:
    • Create the environment (note the 3 in python3):
python3 -m venv venv
  • Activate it by running the following command:
source venv/bin/activate
  • Your terminal prompt will now start with (venv).
  • Install Required Tools:
pip install python-whois requests tqdm

For Linux Users

The process for Linux is very similar to macOS.

  • Install Python & Venv: Most Linux distros come with Python 3. You might just need to install the venv package. On Debian/Ubuntu-based systems, open your terminal and run:
sudo apt-get update
sudo apt-get install python3-venv
  • Install PIP if missing
sudo apt-get install python3-pip
  • Create Your Project Folder:
cd ~/Desktop
mkdir DomainFinder
cd DomainFinder
  • Set Up the Virtual Environment:
    • Create the environment:
python3 -m venv venv
  • Activate it:
source venv/bin/activate
  • Your terminal prompt will now show (venv).
  • Install Required Tools:
pip install python-whois requests tqdm

Fantastic! Your workshop is now set up and ready for action, no matter what system you’re on.

πŸ’‘ Step 2: Getting Your API Key (The Secret Weapon)

Our script’s fallback plan relies on WhoAPI. To use their service, you need a free API key.

  1. Sign Up: Go to the WhoAPI website and sign up for a free account that gives you 10,000 free search every month which we will use as fall back if default tool that we installed hit the limit. This way you can do more that 10,000 search. If you use it a lot and looking for the cheapest option after hitting the limit, you can search for domainr.com, but this will get cheaper than WhoAPI only if you have minimum 50,000 search each month.
  2. Find Your Key: After you log in, navigate to your dashboard. You should see your API key displayed prominently. It will be a long string of letters and numbers.
  3. Copy It: Copy this key. You’ll need to paste it into our script in a moment.

πŸ‘¨β€πŸ’» Step 3: Understanding the Code, Piece by Piece

Now for the fun part. We’re going to build the script. Don’t just copy and paste; read through the explanations to understand how it works. This knowledge is what separates a script user from a script creator.

We’ll place the full, final code at the end of the article, but here’s the breakdown.

Part 1: The Control Panel (Configuration)

At the very top of our script, we’ll have a configuration section. This is where you can easily change what the script searches for without touching the main logic.

# --- Configuration ---
# ⚠️ IMPORTANT: Paste your WhoAPI key here.
WHOAPI_KEY = "YOUR_WHOAPI_KEY_HERE"

# --- Customize Your Search Here ---
# Set the desired length of the domain name (e.g., 3 or 4)
DOMAIN_LENGTH = 3

# Set the desired extension (e.g., "com", "org", "io", "ai")
DOMAIN_EXTENSION = "com"

# Delay between queries in seconds to be a good internet citizen.
QUERY_DELAY = 2

This is the heart of customization!

  • Want to find 4-letter domains? Change DOMAIN_LENGTH = 3 to DOMAIN_LENGTH = 4.
  • Looking for a cool .io or .org domain? Change DOMAIN_EXTENSION = “com” to DOMAIN_EXTENSION = “io”. It’s that simple.

Part 2: The Logic

The script is broken into a few functions, each with a specific job.

  • check_with_whoapi(domain_name): This is our fallback plan. It takes a domain name, contacts WhoAPI with your key, and returns a clear True (available), False (taken), or None (error). It’s also smart enough to detect if you’ve hit your API rate limit.
  • check_domain_direct(domain_name): This is our primary tool. It performs the direct WHOIS check. The clever part here is how it handles errors. If it gets a PywhoisError, it knows this usually means “No match for domain found,” which is exactly what we want! It correctly marks the domain as available. For any other weird error (like a network timeout), it wisely calls the check_with_whoapi function to get a final verdict.
  • main(): This is the main orchestrator. It reads your configuration (DOMAIN_LENGTH, etc.), generates all the letter combinations using Python’s powerful itertools, and then loops through every single one. It uses a library called tqdm to show you a beautiful progress bar in your terminal so you can see how the search is going. For each domain, it calls check_domain_direct and writes the result to the correct log file.

βœ… Step 4: The Complete Code

search-domain

Here it isβ€”the complete, fully commented script. Create a file named domain_finder.py inside your project folder and paste this code into it. Don’t forget to replace this YOUR_WHOAPI_KEY_HERE with actual API key.

# -----------------------------------------------------------------------------
#
#                    Automatic Short Domain Finder
#
# This script automatically searches for available short-letter domain names.
# It first attempts a direct, fast WHOIS query and, if that fails or is
# inconclusive, falls back to the reliable WhoAPI service.
#
# -----------------------------------------------------------------------------

import whois
import requests
import itertools
import string
import time
import sys
from whois.parser import PywhoisError
from tqdm import tqdm

# --- Configuration ---
# ⚠️ IMPORTANT: Paste your WhoAPI key here. Get one from https://whoapi.com/
WHOAPI_KEY = "YOUR_WHOAPI_KEY_HERE"

# --- Customize Your Search Here ---
# Set the desired length of the domain name (e.g., 3 for 'aaa', 4 for 'aaaa')
DOMAIN_LENGTH = 4

# Set the desired extension (e.g., "com", "org", "io", "ai") without the dot.
DOMAIN_EXTENSION = "com"

# Delay between queries in seconds. 2 seconds is recommended to be respectful
# to WHOIS servers and avoid getting your IP address blocked.
QUERY_DELAY = 2

# --- Core Functions ---

def check_with_whoapi(domain_name):
    """
    Fallback method: Checks domain availability using the WhoAPI service.
    This is called when the direct WHOIS check fails.
    """
    if WHOAPI_KEY == "YOUR_WHOAPI_KEY_HERE":
        tqdm.write(f"  └─ ⚠️ WhoAPI key not configured for {domain_name}. Skipping API check.")
        return None # Cannot determine status

    params = {'domain': domain_name, 'r': 'whois', 'apikey': WHOAPI_KEY}
    api_url = "https://whoapi.com/api/v1"

    try:
        response = requests.get(api_url, params=params)
        response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
        data = response.json()

        # Check for specific API error messages like rate limiting
        if data.get("status") == 0 and "rate limit" in data.get("status_message", "").lower():
            tqdm.write(f"  └─ 🚫 WhoAPI rate limit hit for {domain_name}. Increase delay or check plan.")
            return None

        # Check the definitive registration status from the API
        if data.get('registered') is False:
            tqdm.write(f"  └─ βœ… Available (confirmed by WhoAPI)")
            return True
        elif data.get('registered') is True:
            tqdm.write(f"  └─ ➑️ Taken (confirmed by WhoAPI)")
            return False
        else:
            # Handle other unexpected API responses
            status_message = data.get('status_message', 'Unknown response')
            tqdm.write(f"  └─ ❓ Unknown API response for {domain_name}: {status_message}")
            return None

    except requests.exceptions.RequestException as e:
        tqdm.write(f"  └─ ❌ WhoAPI request failed for {domain_name}: {e}")
        return None

def check_domain_direct(domain_name):
    """
    Primary Method: Attempts a direct WHOIS query with intelligent error handling.
    """
    try:
        # Perform the WHOIS lookup
        domain_info = whois.whois(domain_name)
        # If a creation_date exists, it's definitely registered.
        if domain_info.creation_date:
            tqdm.write(f"➑️ Taken: {domain_name}")
            return False
        else:
            # If there's a record but no date, it could be available.
            tqdm.write(f"βœ… Available: {domain_name} (Record found but no date)")
            return True

    except PywhoisError:
        # This specific error almost always means "No match for domain,"
        # which is exactly what we want! It means the domain is available.
        tqdm.write(f"βœ… Available: {domain_name} (WHOIS reports no match)")
        return True

    except Exception as e:
        # For any other exception (network timeout, throttled query, etc.),
        # we fall back to our reliable API check.
        tqdm.write(f"⚠️ Direct WHOIS failed for {domain_name} ({type(e).__name__}). Falling back...")
        return check_with_whoapi(domain_name)

def main():
    """
    The main function that orchestrates the entire process.
    """
    print("πŸš€ Starting Automatic Domain Finder...")
    if WHOAPI_KEY == "YOUR_WHOAPI_KEY_HERE":
        print("\n### WARNING: WhoAPI key not set. The script will be less reliable. ###\n")

    chars = string.ascii_lowercase
    total_domains = len(chars)**DOMAIN_LENGTH
    
    print(f"Configuration: Searching for {DOMAIN_LENGTH}-letter domains with the .{DOMAIN_EXTENSION} extension.")
    print(f"Total domains to check: {total_domains:,}")
    est_hours = (total_domains * QUERY_DELAY) / 3600
    print(f"Estimated time with {QUERY_DELAY}s delay: {est_hours:.2f} hours")
    print("-" * 50)
    
    # Generate all possible letter combinations for the specified length
    domain_combos = itertools.product(chars, repeat=DOMAIN_LENGTH)

    # Open files to log our results. The 'with' statement ensures they are closed properly.
    with open("available_domains.txt", "w") as available_log, \
         open("taken_domains.txt", "w") as taken_log, \
         open("error_domains.txt", "w") as error_log:

        # Wrap our iterator with tqdm to create a beautiful progress bar
        domain_iterator = tqdm(domain_combos, total=total_domains, desc="Scanning Domains", unit="domain")

        for combo in domain_iterator:
            # Join the letters ('a', 'a', 'a') into a string "aaa" and add the extension
            domain_name = ''.join(combo) + '.' + DOMAIN_EXTENSION
            
            # Check the status of the domain
            status = check_domain_direct(domain_name)

            # Log the result to the appropriate file
            if status is True:
                available_log.write(domain_name + '\n')
                available_log.flush() # Write to disk immediately
            elif status is False:
                taken_log.write(domain_name + '\n')
                taken_log.flush()
            else: # status is None, indicating an error in both checks
                error_log.write(domain_name + '\n')
                error_log.flush()

            # The crucial delay to be a good internet citizen
            time.sleep(QUERY_DELAY)

    print("\n" + "-" * 50)
    print("πŸŽ‰ All checks complete! Your results are saved in:")
    print("- available_domains.txt")
    print("- taken_domains.txt")
    print("- error_domains.txt")

if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        # This allows you to stop the script gracefully with Ctrl+C
        print("\n\nProcess interrupted by user. Exiting gracefully.")
        sys.exit(0)

πŸƒ Step 5: Let’s Run This Thing!

You’ve done all the hard work. Your workshop is set up, and your powerful script is ready. Time to unleash it.

  1. Save the Code: Make sure you’ve saved the code above as domain_finder.py in your project folder (DomainFinder).
  2. Fill in Your Details: Open the file and replace "YOUR_WHOAPI_KEY_HERE" with the key you copied. Then, set DOMAIN_LENGTH and DOMAIN_EXTENSION to whatever you want to search for first.
  3. Open Your Terminal/Command Prompt: Navigate back to the window you used to set up the virtual environment.
  4. Activate the Environment (if needed): If you closed the window, you’ll need to reactivate the environment.
    • On Windows: .\venv\Scripts\activate
    • On macOS/Linux: source venv/bin/activate
  5. Run the Script: Now, simply run the file using Python:python domain_finder.py

You should see the script start up, print your configuration, and then the tqdm progress bar will appear and slowly start ticking away. You’ll see status messages for each domain print above the bar.

Now you can sit back, grab a coffee, and let your robot do the work. To stop the script at any time, just press Ctrl+C.

Once it’s done (or you stop it), you can open the .txt files in your project folder to see the results. Happy domain hunting!