Uncategorized

check_dnsbl.py

#!/usr/bin/python3

from pydnsbl import DNSBLChecker
import sys

ips=['xxx.xxx.xxx.xxx','xxx.xxx.xxx.xxx']
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")
    for x in mylist:
        print(x)
    sys.exit(2)
else:
    print("OK -" + " " +str(mylist2))
    sys.exit(0)