Python script to perform WHOIS lookups on a list of domains

Python script to perform WHOIS lookups on a list of domains, along with explanations and considerations

2024-05-17 12:33:40 - Beritau

import whois


def bulk_whois_lookup(domains):
    results = {}
    for domain in domains:
        try:
            whois_data = whois.whois(domain)
            results[domain] = whois_data
        except whois.parser.PywhoisError:
            results[domain] = "WHOIS data not available"
    return results


# Your domain list
domains = ["google.com", "example.org", "nonexistentdomain.net"]

# Perform WHOIS lookups
whois_results = bulk_whois_lookup(domains)

# Print the results in a user-friendly way
for domain, data in whois_results.items():
    print(f"\nWHOIS information for {domain}:")
    if isinstance(data, str):
        print(data)
    else:
        for key, value in data.items():
            print(f"{key}: {value}")


How it Works:

  1. Import the whois library: This library provides functions to interact with WHOIS servers. Make sure you have it installed (pip install python-whois).
  1. Domain list: Define your list of domains.
  2. Perform lookups: Call the bulk_whois_lookup function with your domain list.
  3. Display results: Loop through the results dictionary and print the information for each domain in a formatted manner. If data is not available, it prints the corresponding message.

Key Considerations:

Example Output:

WHOIS information for google.com: ... (WHOIS data for google.com) ... WHOIS information for example.org: ... (WHOIS data for example.org) ... WHOIS information for nonexistentdomain.net: WHOIS data not available

Advanced Options:


More Posts