From 708e4b70755ecb71e63602077f2424965f277049 Mon Sep 17 00:00:00 2001 From: Georg Date: Thu, 26 Aug 2021 17:30:38 +0200 Subject: [PATCH] Improved debug and manual query Signed-off-by: Georg --- __pycache__/plugin.cpython-38.pyc | Bin 8248 -> 8505 bytes plugin.py | 59 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/__pycache__/plugin.cpython-38.pyc b/__pycache__/plugin.cpython-38.pyc index 461f9d94d4d2abe8a7376f916948b79b5a7ea095..7fa3b98ddaf226a44bdf694998dc954a782bd958 100644 GIT binary patch delta 3236 zcma)8-ESMm5x+g&9gh@AeNiGsiPBkeV#}6YJE?3{i9aZcvE;~O;hXn*-4gsg{PINl+1TekpXU1j9xB|GRfgFKvlC_=W}V8|6_BViAc)K!Z1=@&s? zJz77fk*C7$JU6@viXxW{!>I1ubDq;F0#eQ=Pz370`l?R8-XoWk%us{g*I>nEyJMT~ zlQkY{oScWTGLnqX&P5W*Si+c$P0U|2&KL_*v(w4N#C+UXm`+U@(MWVEHg2R6^RddA z|5y99$V@U;nK@d$cG$YmHzM&#BRZQ%#G)x9nTjM*)A4IYbSjdFL{qWEuuSY40q<1h z`a#=^&mrD4y^xp%d&$(fLzZ1+3XEDxu2e8BHD5^Mk~mUi2*f1HZnp%2HvkSRJ+(&wOy$j`D7h=V1-#NFW%N+mj=Hm{7Tnh z5Qk0?hfbwx9btahG?2=52UP$&p`H%tCWSgT6zDSq2Tc35gjMQ}WW%RKOYX0_a(eayc)uW2q!l%&!mYc4mgf;=R&}rKHJ9$#P|jY4*(Hx!|;S zW3m7mq_r`$^9`!tunDjvZW`4Csq)A^#2ns}uke(2!cQdVfeHzdbJ8t1^i_pAD9WK# zc~d3j@?Lr%byQi^HWBf&W$&FDWKO4U?1m=x;TGzoI(1PuZJ{3O#hxv_+KRoj75jQ5 z$X+X;Hi6m!bqLf6$S+VApl*Qz)Cbx@c&x98=n*0IrH;d>OST#0ilD$n{;1p&~+cAYksgx z)n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^M` zfUKD_vkOyWS+)ZM_H*%dvN!q(NcfGguPi?i|4t^12XHSgQYnwDi-)P?@eD4j|1P@W zc?C9&;{`NtfT`(sSgy#naEu$X2jVZOb1j{1p$@anw!&e}DvGpSBtI4(+9$~=@hAHh GdFMZ}RPW&c diff --git a/plugin.py b/plugin.py index 10eddb5..d47440f 100644 --- a/plugin.py +++ b/plugin.py @@ -78,16 +78,17 @@ class SnoParser(callbacks.Plugin): asn = 0 subnet = '' try: - whois = IPWhois(sourceip) - whoisres = whois.lookup_rdap(depth=1,retry_count=0) - results = whoisres - print(results) - asn = whoisres['asn_registry'] - country = whoisres['asn_country_code'] - description = whoisres['asn_description'] - whoisout = '# ' + asn + ' ' + country + ' ' + description + whois = IPWhois(sourceip) + whoisres = whois.lookup_rdap(depth=1,retry_count=0) + results = whoisres + if self.registryValue('whois.debug'): + print(results) + asn = whoisres['asn_registry'] + country = whoisres['asn_country_code'] + description = whoisres['asn_description'] + whoisout = asn + ' ' + country + ' ' + description except ipwhois.exceptions.IPDefinedError: - whoisout = 'RFC 4291 (Local)' + whoisout = 'RFC 4291 (Local)' response = whoisout return response @@ -114,30 +115,30 @@ class SnoParser(callbacks.Plugin): data = self.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) - #data["cache"] = True - print("DEBUG - CACHE: TRUE") - print(data) - print(sourceip) + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: TRUE") + print(data) + print(sourceip) return data else: data = self.whois_fresh(sourceip) - print("DEBUG - ELSE WHOIS_FRESH CALLED") - print(data) - print(sourceip) - if data.startswith("#"): - #data["cache"] = False - print("DEBUG - CACHE: FALSE") + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE") + print(data) + print(sourceip) + if data.startswith: + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG - WHOIS_RUN WITH CACHE: FALSE AND CORRECT STARTING CHARACTER") + print(data) data = json.dumps(data) state = self.whois_set_cache(key=sourceip, value=data) - print(data) - print(sourceip) - if state is True: return json.loads(data) else: - print("Data does not start with correct string") - print(data) + if self.registryValue('whois.debug'): + print("SNOPARSER DEBUG _ WHOIS_RUN WITH CACHE: FALSE AND WRONG STARTING CHARACTER") + print(data) return data def query(self, irc, msg, args, ipaddress): @@ -146,11 +147,11 @@ class SnoParser(callbacks.Plugin): """ data = self.whois_get_cache(key=ipaddress) - ttl = self.redis_client.get(ipaddress) + decoded = data.decode('utf-8') + ttl = self.redis_client.ttl(ipaddress) - print(data, ' ', ttl) - #irc.reply(str(data), ' Remaining: ', int(ttl), 's') - irc.reply(data, ttl) + print('SnoParser manual query: ', data, ' ', ttl) + irc.reply(f'{decoded} - Remaining: {ttl}s') query = wrap(query, ['anything']) @@ -174,8 +175,6 @@ class SnoParser(callbacks.Plugin): realname = couple.group(5) ip_seen = 0 nick_seen = 0 - asn = 0 - subnet = '' whoisout = self.whois_run(sourceip=ip) DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen}