summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg2021-08-26 17:30:38 +0200
committerGeorg2021-08-26 17:38:21 +0200
commit708e4b70755ecb71e63602077f2424965f277049 (patch)
tree6fa7d2e1973b1e80202c380baa89b9c8c7192aca
parenta458460cec77aceefdcd9b966e5c1813ea16c883 (diff)
downloadsnoparser-708e4b70755ecb71e63602077f2424965f277049.tar.gz
snoparser-708e4b70755ecb71e63602077f2424965f277049.tar.bz2
snoparser-708e4b70755ecb71e63602077f2424965f277049.zip
Improved debug and manual query
Signed-off-by: Georg <georg@lysergic.dev>
-rw-r--r--__pycache__/plugin.cpython-38.pycbin8248 -> 8505 bytes
-rw-r--r--plugin.py59
2 files changed, 29 insertions, 30 deletions
diff --git a/__pycache__/plugin.cpython-38.pyc b/__pycache__/plugin.cpython-38.pyc
index 461f9d9..7fa3b98 100644
--- a/__pycache__/plugin.cpython-38.pyc
+++ b/__pycache__/plugin.cpython-38.pyc
Binary files differ
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}