How to Find the whois Information about a Domain Name or IP Address in Python



Python


In this article, we show how to find the whois information about a domain name or IP address in Python.

This tells us information about the domain name or IP address, such as its registrar, its server, its creation date, its name servers, the organization name, the organization address, including its city, state, postal code, and country.

In order to find out this information in Python, the first thing you will need is the whois module in Python.

This is obtained through the following line shown below.





So after you have this module installed, we have the following code shown below to get information about the bing.com website. You can change this out for any other website.





So let's now go over the code.

Of course, we have to import the whois module before we can use it.

We create a class, WhoisInfo.

We then create a function, print_whois_info(), that prints the whois information for whatever website is specified for host.

We then have our main function, which runs the code for bing.com in this instance.

A much simpler version of this code





The code above produces the following output shown below.





You can see that it gives us a good amount of information for the domain name.

We see that the organization is Microsoft Corporation, which is the owner of the Bing website and search engine.

The address is One Microsoft Way, Redmond, WA 98052, which is where Microsoft has been since its inception.

We can see a Python dictionary of emails, which are associated with the microsoft domain name.

We can also see that the domain name registrar is MarkMonitor, Inc., which is a corporate domain management company. We can see that this server was originally created on 1/29/1996.

So you can do this for any domain name.

You can also do it for IP addresses.

The IP address for bing.com is 204.79.197.200

So we will now run our program but with the IP address instead of the domain name, which should work as well.

So running this program, we get similar output, as shown below.





So you can see that we can get the whois information about a domain name or IP address through the whois Python module.

Of course, change the domain names and IP addresses to see what results you get for other values.


Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...