2015-02-01 13:29:22 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import pythonwhois
|
|
|
|
import argparse
|
|
|
|
import sys
|
2015-02-01 17:51:11 +02:00
|
|
|
import itertools
|
2015-02-01 13:29:22 +02:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='Check whois and dns information.')
|
|
|
|
parser.add_argument('--domain', nargs=1, required=True, help='the domain name')
|
2015-02-01 17:51:11 +02:00
|
|
|
parser.add_argument('--nameserver', nargs='+', help='a space delimited list of nameservers')
|
2015-02-01 13:29:22 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2015-02-01 17:51:11 +02:00
|
|
|
nsargs = args.nameserver
|
|
|
|
# how many ns servers should we expect?
|
|
|
|
nsargscount = len(nsargs)
|
|
|
|
|
2015-02-01 13:29:22 +02:00
|
|
|
try:
|
2015-02-01 17:51:11 +02:00
|
|
|
whois = pythonwhois.get_whois(args.domain[0])
|
|
|
|
whoiscount = []
|
2015-02-04 17:28:07 +02:00
|
|
|
|
2015-02-01 17:51:11 +02:00
|
|
|
for key, value in whois.iteritems():
|
|
|
|
if key == "nameservers":
|
|
|
|
whoiscount.append(value)
|
2015-02-01 13:29:22 +02:00
|
|
|
except:
|
|
|
|
#something happened, raise an erro
|
2015-02-01 17:51:11 +02:00
|
|
|
print "3 Unexpected_error: ", sys.exc_info()[0]
|
|
|
|
|
|
|
|
# how many nameservers did whois return?
|
|
|
|
#whoiscount = reduce(lambda x,y: x.extend(y),whoiscount)
|
2015-02-04 17:28:07 +02:00
|
|
|
#print len(whoiscount)
|
|
|
|
#print nsargscount
|
2015-02-01 17:51:11 +02:00
|
|
|
nscount = list(itertools.chain.from_iterable(whoiscount))
|
2015-02-04 17:28:07 +02:00
|
|
|
#print len(nscount)
|
2015-02-01 17:51:11 +02:00
|
|
|
|
|
|
|
if len(nscount) < nsargscount:
|
2015-02-04 17:28:07 +02:00
|
|
|
print("Extended_DNS_Check CRITICAL - WHOIS DNS servers do not match provided DNS nameservers.")
|
|
|
|
sys.exit(2)
|
2015-02-01 17:51:11 +02:00
|
|
|
elif len(nscount) > nsargscount:
|
2015-02-04 17:28:07 +02:00
|
|
|
print("Extended_DNS_Check WARNING - WHOIS DNS servers do not match. There are more DNS servers from the WHOIS datbase than in your query.")
|
|
|
|
sys.exit(1)
|
2015-02-01 17:51:11 +02:00
|
|
|
else:
|
2015-02-04 17:28:07 +02:00
|
|
|
print("Extended_DNS_Check OK - all DNS server match")
|
|
|
|
sys.exit(0)
|