Uncategorized

check_dnsbl.py

#!/usr/bin/python3

from pydnsbl import DNSBLChecker
import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument(‘-l’, ‘–list’, help=’delimited list input’, type=str)
args = parser.parse_args()
ips = [str(item) for item in args.list.split(‘,’)]

checker = DNSBLChecker()
mylist=[]
mylist2=[]

for ip in ips:
result = checker.check_ip(ip)
if result.blacklisted is True:
mylist.append(ip)

else:
mylist2.append(ip)
if len(mylist) > 0:
size=len(mylist)
print(“Critical -” + ” ” +str(size) + ” ” + “IP” + ” ” + “blacklisted”)
print(mylist)
sys.exit(2)
else:
print(“OK -” + ” ” +str(mylist2))
sys.exit(0)