Domain WHois

Domain WHois Another Version

2024-10-26 19:50:35 - Coderja

import whois

def get_specific_whois_data(domain):
    try:
        whois_data = whois.whois(domain)
        data_to_extract = {
            "domain_name": domain,
            "registrar": whois_data.registrar if hasattr(whois_data, 'registrar') else "N/A",
            "expiration_date": whois_data.expiration_date[0].strftime("%Y-%m-%d") if (hasattr(whois_data, 'expiration_date') and isinstance(whois_data.expiration_date, list)) else whois_data.expiration_date.strftime("%Y-%m-%d") if (hasattr(whois_data, 'expiration_date') and whois_data.expiration_date is not None) else "N/A",
            "name_servers": ", ".join(whois_data.name_servers) if (hasattr(whois_data, 'name_servers') and isinstance(whois_data.name_servers, (list, tuple))) else "N/A"
        }
        return data_to_extract
    except whois.parser.PywhoisError:
        print(f"Error getting WHOIS for {domain}. Skipping...")
        return None

# Read domains from list.txt
with open("list.txt", "r") as file:
    domains = [line.strip() for line in file]

# Process domains and update files
processed_domains = []
for domain in domains:
    result = get_specific_whois_data(domain)
    if result:
        with open("results.txt", "a") as file:
            file.write(f"{result['domain_name']}, {result['registrar']}, {result['expiration_date']}, {result['name_servers']}\n")
        processed_domains.append(domain)
    
    # Remove processed domains from list.txt
    with open("list.txt", "w") as file:
        for remaining_domain in set(domains) - set(processed_domains):
            file.write(remaining_domain + "\n")

print("WHOIS lookup completed.")

More Posts