#!/usr/bin/python3 -s
# vim:expandtab shiftwidth=4 softtabstop=4 tabstop=8

from rblwatch import RBLSearch
import socket

try:
    hostname = socket.gethostname() + '.'
    for response in socket.getaddrinfo(hostname, None, 0, 1):
        ip = response[4][0]
        searcher = RBLSearch(ip)
        listed = searcher.listed
        for key in listed:
            if key == 'SEARCH_HOST':
                continue
            if not listed[key].get('ERROR'):
                if listed[key]['LISTED']:
                    print("Results for %s: %s" % (key, listed[key]['LISTED']))
                    print("  + Host information: %s" % \
                          (listed[key]['HOST']))
                if 'TEXT' in listed[key].keys():
                    print("    + Additional information: %s" % \
                          (listed[key]['TEXT']))
            else:
                pass
except:
    print("Hostname %s can't be resolved" % hostname)
    ip = ""

