What is Python-Whois?.
Python-whois is a python library that is used to obtain information about registered domain names, IP addresses, etc. With its simple API and powerful parsing capabilities, it is a valuable tool for any Python developer working with internet infrastructure.
The Python-whois library makes it easy to query WHOIS servers and retrieve raw WHOIS data. It then provides a variety of helper functions for working with this data, including functions for parsing and extracting specific pieces of information, such as creation and expiration dates, registrant and contact information, and more
Now Let’s Look at how to install this library
How to install the Python-Whois library?
You can simply install this library on your device by using pip. You can refer to the below command to install this library
pip install python-whois
Once the library is installed, you can use it to retrieve WHOIS information for a given domain name using the whois
function:
Now let’s create a simple code that will retrieve some information about the domain using the whois library. You can refer to the below code on how to retrieve basic information about the domain using whois
import whois
domain = "ideasorblogs.in"
w = whois.whois(domain)
print(w)
This will print out a dictionary containing the WHOIS information for the domain. The exact fields returned can vary depending on the domain and the WHOIS server being queried.
You can see an example response while running this code below
{
"domain_name": "ideasorblogs.in",
"registrar": "GoDaddy.com, LLC",
"registrar_url": "www.godaddy.com",
"registrar_iana": "146",
"updated_date": "2023-02-06 13:58:56",
"creation_date": "2022-12-27 16:45:24",
"expiration_date": "2023-12-27 16:45:24",
"name_servers": [
"ns1.dns-parking.com",
"ns2.dns-parking.com"
],
"organization": null,
"state": "Andhra Pradesh",
"status": [
"clientUpdateProhibited http://www.icann.org/epp#clientUpdateProhibited",
"clientTransferProhibited http://www.icann.org/epp#clientTransferProhibited",
"clientDeleteProhibited http://www.icann.org/epp#clientDeleteProhibited",
"clientRenewProhibited http://www.icann.org/epp#clientRenewProhibited"
],
"emails": null,
"country": "IN",
"dnssec": "unsigned"
}
Here you can see in this example response we collected information about the data of the domain like registrar details, registrar URL, updated date, creation date, expiration date, name servers, etc
In addition to retrieving the basic WHOIS information, the Python-whois library also provides several helper functions for working with the data.
For example, You can also extract the registrant, administrative, and technical contact information like this:
import whois
domain = "ideasorblogs.in"
w = whois.whois(domain)
print("Registrant:", w.registrant)
print("Admin contact:", w.admin_contact)
print("Tech contact:", w.tech_contact)
Python-whois also provides some useful helper functions for working with WHOIS data. For example, you can use the parse
function to convert raw WHOIS data into a structured dictionary
With this library, you can add many advanced features to your code and create an advanced code that will help you to find information about the domain. Hope this article will give an idea about how to create a Domain information collector using whois library
- pybase64 encode and decode Messages using Python - June 6, 2023
- Different Data Types in Dart - June 6, 2023
- What is flutter and dart and the difference - June 4, 2023