How to get Domain Information in Python
Getting Domain Information In Python.
Through this article, we’ll learn how to validate domain names using WHOIS, as well as getting domain name information such as domain
registrar, creation date, expiration date, and more in Python.
Topics that we’ll cover through this article are as follows:
- About package
- Syntax of Installation & Importation
- Usage Example:
“whois” is a python package which is used for retrieving WHOIS
Information of domains such as registrar, creation date, expiration date
etc. It works smoothly with python 2.4x and more without any external dependencies.
Syntax of Installation:
pip install python-whois
Syntax of Importation:
- It is a simple interface to access parsed WHOIS data for a given Domain.
- This has the ability to extract data for all popular TLDs (Top-Level Domains) like com, org, net,….It is the last segment of a domain name after the final dot. A great example of a TDL is: .com The IANA (Internet Assigned Numbers Authority) officially recognizes five types of TLDs:
- ARPA – Infrastructure Top-Level Domain: It was the first internet top-level domain and intended to use temporarily aiding in the transition of traditional ARPANET host names to DNS. Due to historical reasons, it is sometimes considered to be a gTLD.
- gTLD – Generic Top-Level Domains: These are one of the categories of TLDs maintained by IANA for use in the DNS of the internet. The core group of gTLD consists of the com, info, net, and org domains.
- STLD – Sponsored Top-Level Domains: IT is a specialized TLD that has a sponsor representing a specific community served by the domain. The companies involved are based on geographical, professional, technical, ethnic, or other themes. The core group of sTLD consists of aero, Asia, cat, coop, edu, gov, jobs, travel, etc.
- ccTLD – Country Code Top-Level Domains: It is an internet TLD, used and reserved for a country, sovereign state, or dependent territory. There are 312 ccTLD in active use, some of the ccTLD’s are the UK, us, de, cn, etc.
- tTLD – Test Top-Level Domains: This TLD is intended for the use in testing of software. It is reserved type TLD to prevent conflicts and confusion. This TLD is used in documentation or for internal testing.
Note: TLD plays an important role in DNS(Domain Name System).
- Instead of going through intermediate web services, it directly queries the WHOIS server and parses WHOIS data for a given domain.
- It has the ability to reformat WHOIS data for better human readability i.e WHOIS Data Normalization.
- It provides an automated testing suite.
Let’s begin with a domain and try to get its WHOIS information. Here, I am using a generic Top-Level Domain.
So let’s see how we can validate domain name using WHOIS, and get domain name information such as domain registrar, creation date, expiration date, and other information too.
#importing whois package import whois # defining a function that returns a boolean indicating whwther a 'domain_name' is registered or not. def is_registered(domain_name): try: w = whois.whois(domain_name) except Exception: return False else: return bool(w.domain_name) if __name__ == '__main__': domain_name = input("Please enter any domain name: ") if is_registered(domain_name): whois_info = whois.whois(domain_name) #print the name of registrar print("DOMAIN REGISTRAR: ",whois_info.registrar) # print the WHOIS server print("WHOIS SERVER: ", whois_info.whois_server) # Print the cration date print("Domain Creation Date: ",whois_info.creation_date) #print the expiration date print("Expiration Date: ", whois_info.expiration_date) #print all information related to whois print(whois_info)
here, we can see all the WHOIS information about the typed domain name.
Liked our content? 😊 then don’t forget to share and comment.
Thank you for reading this article, in the upcoming article we will learn more python programming.