Code for How to Get Domain Name Information in Python Tutorial

View on Github

import whois # pip install python-whois

def is_registered(domain_name):
    A function that returns a boolean indicating 
    whether a `domain_name` is registered
        w = whois.whois(domain_name)
    except Exception:
        return False
        return bool(w.domain_name)

if __name__ == "__main__":
    # list of registered & non registered domains to test our function
    domains = [
    # iterate over domains
    for domain in domains:
        print(domain, "is registered" if is_registered(domain) else "is not registered")

import whois
from validate_domains import is_registered

domain_name = ""
if is_registered(domain_name):
    whois_info = whois.whois(domain_name)
    # print the registrar
    print("Domain registrar:", whois_info.registrar)
    # print the WHOIS server
    print("WHOIS server:", whois_info.whois_server)
    # get the creation time
    print("Domain creation date:", whois_info.creation_date)
    # get expiration date
    print("Expiration date:", whois_info.expiration_date)
    # print all other info