-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwho.py
37 lines (30 loc) · 925 Bytes
/
who.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import whois # pip install python-whois
import sys
if (len(sys.argv)<2):
print("usage: " + sys.argv[0] + "<url>")
sys.exit()
def is_registered(domain_name):
"""
A function that returns a boolean indicating
whether a `domain_name` is registered
"""
try:
w = whois.whois(domain_name)
except Exception:
return False
else:
return bool(w.domain_name)
# test with Google domain name
domain_name = sys.argv[1]
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
print(whois_info)