forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domaincheck.py
executable file
·41 lines (36 loc) · 1.46 KB
/
domaincheck.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
38
39
40
41
#!/usr/bin/env python
import sys
import whois
# python-whois from pypi, not whois from pypi or python-whois from debian
# https://bitbucket.org/richardpenman/pywhois
import datetime
from dateutil.relativedelta import relativedelta
format="%25s %10s %3s %s"
if __name__ == '__main__':
domainlist = []
for name in sys.argv[1:]:
domain = whois.whois(name)
if not domain["expiration_date"]:
print("Can't get expiration date for %s" % name)
continue
elif hasattr(domain["expiration_date"], "__len__"):
# Sometimes python-whois returns a list of dates,
# for unknown reasons.
# Check whether they're all the same.
expdate = domain["expiration_date"][0].date()
for e in domain["expiration_date"][1:]:
if e.date() != expdate:
print("Yikes, %s != %s" % (str(e), str(expdate)))
else:
expdate = domain["expiration_date"].date()
domainlist.append((name, expdate, domain.registrar))
domainlist.sort(key = lambda a: a[1])
two_months_from_now = datetime.datetime.today() + relativedelta(months=2)
two_months_from_now = two_months_from_now.date()
print(format % ("Domain", "Expires", "", "Registrar"))
for d in domainlist:
if d[1] < two_months_from_now:
alert = "***"
else:
alert = ""
print(format % (d[0], d[1].strftime('%Y-%m-%d'), alert, d[2]))