I'd to create a script to find all domain names that include a specific term. How can I…
- User
I'd to create a script to find all domain names that include a specific term. How can I do that?
Assistant
Creating a script to find all domain names that include a specific term involves several steps. You can use a combination of WHOIS databases, domain registrars' APIs, or web scraping techniques. Below is a Python-based approach using the
whoislibrary and public APIs to search for domain names containing a specific term.Prerequisites
-
Install Required Libraries:
pip install python-whois pip install requests -
API Keys: Some domain registrars or services may require API keys for bulk lookups. For this example, we'll use a simple approach without API keys.
Script to Find Domain Names Containing a Specific Term
import whois import requests from urllib.parse import quote def find_domains_with_term(term, tld='com', limit=10): """ Find domain names containing a specific term. :param term: The term to search for in domain names. :param tld: The top-level domain to search within (e.g., 'com', 'net', 'org'). :param limit: The maximum number of results to return. :return: A list of domain names containing the term. """ found_domains = [] base_url = f"https://api.domainsdb.info/v1/domains/search?domain={quote(term)}&zone={tld}" try: response = requests.get(base_url) response.raise_for_status() data = response.json() for domain_info in data['domains']: domain_name = domain_info['domain'] if term in domain_name: found_domains.append(domain_name) if len(found_domains) >= limit: break return found_domains except requests.exceptions.RequestException as e: print(f"Error fetching domain data: {e}") return [] def check_domain_availability(domain): """ Check if a domain is available using WHOIS. :param domain: The domain name to check. :return: True if available, False if registered. """ try: w = whois.whois(domain) return w.expiration_date is None except Exception as e: print(f"Error checking domain {domain}: {e}") return False if __name__ == "__main__": search_term = "example" # Replace with your desired term tld_to_search = "com" # Replace with the desired TLD max_results = 10 # Maximum number of results to return domains = find_domains_with_term(search_term, tld_to_search, max_results) print(f"Domains containing '{search_term}' in the '{tld_to_search}' TLD:") for domain in domains: availability = check_domain_availability(domain) status = "Available" if availability else "Registered" print(f"{domain}: {status}")Explanation
-
find_domains_with_termFunction:- Uses the
domainsdb.infoAPI to search for domains containing the specified term within a given TLD. - Filters the results to include only domains that contain the term.
- Uses the
-
check_domain_availabilityFunction:- Uses the
python-whoislibrary to check if a domain is available or already registered.
- Uses the
-
Main Script:
- Calls the functions to find and display domains containing the specified term, along with their availability status.
Alternative Approaches
- Web Scraping: Scrape domain registrars' websites (e.g., GoDaddy, Namecheap) for domain availability.
- Brute Force: Generate permutations of the term and check their availability using WHOIS.
Notes
- Rate Limiting: Be mindful of API rate limits when making bulk requests.
- Accuracy: WHOIS data may not always be up-to-date or accurate.
- Legal Compliance: Ensure your script complies with the terms of service of the APIs or services you use.
This script provides a basic framework. Depending on your needs, you may want to expand it with error handling, logging, or additional features.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.