From 95d6e7856365dd3d58552e6962a54496ab93f0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roge=CC=81rio=20Carrasqueira?= Date: Thu, 26 May 2016 15:18:34 -0300 Subject: [PATCH 1/4] Adding a way to check from my own rbl list --- rblwatch/rblwatch.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rblwatch/rblwatch.py b/rblwatch/rblwatch.py index 0324a32..0f372df 100644 --- a/rblwatch/rblwatch.py +++ b/rblwatch/rblwatch.py @@ -123,13 +123,15 @@ def run(self): self.listed[self.dnslist]['ERROR'] = True self.listed[self.dnslist]['ERRORTYPE'] = NoAnswer + class RBLSearch(object): - def __init__(self, lookup_host): + def __init__(self, lookup_host, my_rbl_list=None): self.lookup_host = lookup_host self._listed = None self.resolver = Resolver() self.resolver.timeout = 0.2 self.resolver.lifetime = 1.0 + self.my_rbl_list = my_rbl_list def search(self): if self._listed is not None: @@ -143,7 +145,13 @@ def search(self): host = re.sub('.ip6.arpa.', '', host) self._listed = {'SEARCH_HOST': self.lookup_host} threads = [] - for LIST in RBLS: + + lists_to_check = RBLS + + if self.my_rbl_list: + lists_to_check = self.my_rbl_list + + for LIST in lists_to_check: self._listed[LIST] = {'LISTED': False} query = Lookup("%s.%s" % (host, LIST), LIST, self._listed, self.resolver) threads.append(query) From a42a8f2a183ea8f279f6b3c4040ec52eef83e0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roge=CC=81rio=20Carrasqueira?= Date: Sat, 28 May 2016 08:28:02 -0300 Subject: [PATCH 2/4] Allowing support to query domains on rbl --- rblwatch/rblwatch.py | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/rblwatch/rblwatch.py b/rblwatch/rblwatch.py index 0f372df..cb86137 100644 --- a/rblwatch/rblwatch.py +++ b/rblwatch/rblwatch.py @@ -98,6 +98,7 @@ def __init__(self, host, dnslist, listed, resolver): self.resolver = resolver def run(self): + try: host_record = self.resolver.query(self.host, "A") if len(host_record) > 0: @@ -137,13 +138,40 @@ def search(self): if self._listed is not None: pass else: - ip = IP(self.lookup_host) - host = ip.reverseName() - if ip.version() == 4: - host = re.sub('.in-addr.arpa.', '', host) - elif ip.version() == 6: - host = re.sub('.ip6.arpa.', '', host) + + try: + ip = IP(self.lookup_host) + except ValueError: + ip = None + self._listed = {'SEARCH_HOST': self.lookup_host} + + if ip: + + host = ip.reverseName() + if ip.version() == 4: + host = re.sub('.in-addr.arpa.', '', host) + elif ip.version() == 6: + host = re.sub('.ip6.arpa.', '', host) + else: + + try: + socket.gethostbyname(self.lookup_host) + host = self.lookup_host + except socket.gaierror: + self._listed['SEARCH_HOST'] = { + 'ERROR': True, + 'ERRORTYPE': socket.gaierror + } + except socket.herror: + self._listed['SEARCH_HOST'] = { + 'ERROR': True, + 'ERRORTYPE': socket.herror + } + + if 'ERROR' in self._listed['SEARCH_HOST']: + return self._listed + threads = [] lists_to_check = RBLS @@ -167,7 +195,12 @@ def print_results(self): print("--- DNSBL Report for %s ---" % listed['SEARCH_HOST']) for key in listed: if key == 'SEARCH_HOST': - continue + if not 'ERROR' in listed['SEARCH_HOST']: + continue + else: + print "Error querying for %s" % self.lookup_host + break + if not listed[key].get('ERROR'): if listed[key]['LISTED']: print("Results for %s: %s" % (key, listed[key]['LISTED'])) From a5168e0bf2afb09a8b3b24a7065f8e1a19dd3865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Carrasqueira?= Date: Tue, 18 Apr 2017 15:52:43 -0300 Subject: [PATCH 3/4] Adjusting treatment when a rbl refuse a query --- rblwatch/rblwatch.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rblwatch/rblwatch.py b/rblwatch/rblwatch.py index cb86137..390aa73 100644 --- a/rblwatch/rblwatch.py +++ b/rblwatch/rblwatch.py @@ -107,6 +107,10 @@ def run(self): text_record = self.resolver.query(self.host, "TXT") if len(text_record) > 0: self.listed[self.dnslist]['TEXT'] = "\n".join(text_record[0].strings) + + if 'query refused' in self.listed[self.dnslist]['TEXT'].lower(): + self.listed[self.dnslist]['LISTED'] = False + self.listed[self.dnslist]['ERROR'] = False except NXDOMAIN: self.listed[self.dnslist]['ERROR'] = True From 9a6570dfdd1d96cb79240153e7997fd6cef6b8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Carrasqueira?= Date: Tue, 18 Apr 2017 15:53:59 -0300 Subject: [PATCH 4/4] Adjusting treatment when a rbl refuse a query --- rblwatch/rblwatch.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rblwatch/rblwatch.py b/rblwatch/rblwatch.py index 390aa73..03a3065 100644 --- a/rblwatch/rblwatch.py +++ b/rblwatch/rblwatch.py @@ -107,11 +107,12 @@ def run(self): text_record = self.resolver.query(self.host, "TXT") if len(text_record) > 0: self.listed[self.dnslist]['TEXT'] = "\n".join(text_record[0].strings) - - if 'query refused' in self.listed[self.dnslist]['TEXT'].lower(): - self.listed[self.dnslist]['LISTED'] = False - self.listed[self.dnslist]['ERROR'] = False + + if 'query refused' in self.listed[self.dnslist]['TEXT'].lower(): + self.listed[self.dnslist]['LISTED'] = False + self.listed[self.dnslist]['ERROR'] = True + except NXDOMAIN: self.listed[self.dnslist]['ERROR'] = True self.listed[self.dnslist]['ERRORTYPE'] = NXDOMAIN