visit
In this tutorial, we will use the whois library to build a simple domain lookup tool. With this tool, we can retrieve domain name information such as the creation date, expiration date, address, country of the owner, and more.
To install python-whois via pip, run the following command:
pip install python-whois # 👉️ Python 2
pip3 install python-whois # 👉️ Python 3
import whois # 👉️ Import whois module
dm_info = whois.whois("gzht888.com") # 👉️ Get Domain Info
print(dm_info)
{
"domain_name": [
"gzht888.com",
"gzht888.com"
],
"registrar": "GoDaddy.com, LLC",
"whois_server": "whois.godaddy.com",
"referral_url": null,
"updated_date": [
"2022-11-03 15:45:14",
"2022-04-04 12:33:12"
],
"creation_date": [
"2016-04-03 23:11:48",
"2016-04-03 18:11:48"
],
"expiration_date": [
"2023-04-03 23:11:48",
"2023-04-03 18:11:48"
],
"name_servers": [
"AMBER.NS.CLOUDFLARE.COM",
"GUY.NS.CLOUDFLARE.COM"
],
"status": [
"clientDeleteProhibited //icann.org/epp#clientDeleteProhibited",
"clientRenewProhibited //icann.org/epp#clientRenewProhibited",
"clientTransferProhibited //icann.org/epp#clientTransferProhibited",
"clientUpdateProhibited //icann.org/epp#clientUpdateProhibited"
],
"emails": "[email protected]",
"dnssec": "unsigned",
"name": "Registration Private",
"org": "Domains By Proxy, LLC",
"address": [
"DomainsByProxy.com",
"2155 E Warner Rd"
],
"city": "Tempe",
"state": "Arizona",
"registrant_postal_code": "85284",
"country": "US"
}
print("Registar:", dm_info.registrar) # 👉️ Get Registar
print("Creation Date:", dm_info.creation_date) # 👉️ Get Creation Date
print("Expiration Date:", dm_info.expiration_date) # 👉️ Expiration Date
print("Country:", dm_info.country) # 👉️ Get Country
Registar: GoDaddy.com, LLC
Creation Date: 2016-04-03 23:11:48
Expiration Date: 2023-04-03 23:11:48
Country: US
dm_info = whois.whois("xysqsw.com") # 👉️ xysqsw.com isn't registered
whois.parser.PywhoisError: No match for "XYSQSW.COM"
try:
dm_info = whois.whois("xysqsw.com") # 👉️ Get Domain Info
print(dm_info)
except:
print("Something Went Wrong")
Something Went Wrong
pip install validators # 👉️ Python 2
pip3 install validators # 👉️ Python 2
is a validation library used to validate email, date, IBAN, and domain...
import validators # pip install validators
def domain_lookup(dm):
if validators.domain(dm): # Check if Domain is Valid
try:
dm_info = whois.whois(dm) # 👉️ Get Domain Info
return dm_info
except:
return f"{dm} is not registered"
else:
return f"Enter a valid domain"
d_i = domain_lookup("facebook.com")
print(d_i)
{
"domain_name": "FACEBOOK.COM",
"registrar": "RegistrarSafe, LLC",
"whois_server": "whois.registrarsafe.com",
"referral_url": null,
"updated_date": "2022-01-26 16:45:06",
"creation_date": "1997-03-29 05:00:00",
"expiration_date": "2031-03-30 04:00:00",
"name_servers": [
"A.NS.FACEBOOK.COM",
"B.NS.FACEBOOK.COM",
"C.NS.FACEBOOK.COM",
"D.NS.FACEBOOK.COM"
],
"status": [
"clientDeleteProhibited //icann.org/epp#clientDeleteProhibited",
"clientTransferProhibited //icann.org/epp#clientTransferProhibited",
"clientUpdateProhibited //icann.org/epp#clientUpdateProhibited",
"serverDeleteProhibited //icann.org/epp#serverDeleteProhibited",
"serverTransferProhibited //icann.org/epp#serverTransferProhibited",
"serverUpdateProhibited //icann.org/epp#serverUpdateProhibited",
"serverUpdateProhibited //www.icann.org/epp#serverUpdateProhibited",
"clientDeleteProhibited //www.icann.org/epp#clientDeleteProhibited",
"clientTransferProhibited //www.icann.org/epp#clientTransferProhibited",
"serverDeleteProhibited //www.icann.org/epp#serverDeleteProhibited",
"serverTransferProhibited //www.icann.org/epp#serverTransferProhibited",
"clientUpdateProhibited //www.icann.org/epp#clientUpdateProhibited"
],
"emails": [
"[email protected]",
"[email protected]"
],
"dnssec": "unsigned",
"name": "Domain Admin",
"org": "Meta Platforms, Inc.",
"address": "1601 Willow Rd",
"city": "Menlo Park",
"state": "CA",
"registrant_postal_code": "94025",
"country": "US"
}
d_i = domain_lookup("blabla123.com")
print(d_i)
blabla123.com is not registered
d_i = domain_lookup("blabla123 h.com")
print(d_i)
Enter a valid domain