summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg2021-08-26 12:50:25 +0200
committerGeorg2021-08-26 12:50:25 +0200
commitf796a296911f71edc80e9e24e33413ce91af9003 (patch)
tree486c55dda848b223b6dcddd9598e6ce37da1078f
parentc4941a26c1f1d127a7eaa315705aedc439edb15d (diff)
downloadsnoparser-f796a296911f71edc80e9e24e33413ce91af9003.tar.gz
snoparser-f796a296911f71edc80e9e24e33413ce91af9003.tar.bz2
snoparser-f796a296911f71edc80e9e24e33413ce91af9003.zip
First working Redis cache
Signed-off-by: Georg <georg@lysergic.dev>
-rw-r--r--__pycache__/plugin.cpython-38.pycbin7286 -> 7481 bytes
-rw-r--r--plugin.py43
2 files changed, 32 insertions, 11 deletions
diff --git a/__pycache__/plugin.cpython-38.pyc b/__pycache__/plugin.cpython-38.pyc
index 70c3898..790a6db 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 7cab169..bfa31a9 100644
--- a/plugin.py
+++ b/plugin.py
@@ -45,6 +45,7 @@ import time
import sqlite3
import redis
import json
+from datetime import timedelta
from ipwhois import IPWhois
import ipwhois
@@ -81,13 +82,16 @@ class SnoParser(callbacks.Plugin):
asn = whoisres['asn_registry']
country = whoisres['asn_country_code']
description = whoisres['asn_description']
- whoisout = asn + ' ' + country + ' ' + description
+ whoisout = 'WHOIS ' + asn + ' ' + country + ' ' + description
except ipwhois.exceptions.IPDefinedError:
whoisout = 'RFC 4291 (Local)'
- rr = f"{results}"
- response = SnoParser.redis_client.get(rr)
- return response.json()
+# rr = f"{results}"
+# response = rr
+# return response.json()
+# response = results
+ response = whoisout
+ return response
def whois_get_cache(key: str) -> str:
"""Data from Redis."""
@@ -98,24 +102,37 @@ class SnoParser(callbacks.Plugin):
def whois_set_cache(key: str, value: str) -> bool:
"""Data to Redis."""
- state = client.setex(key, timedelta(seconds=3600), value=value,)
+ state = SnoParser.redis_client.setex(key, timedelta(seconds=3600), value=value,)
return state
def whois_run(coordinates: str) -> dict:
data = SnoParser.whois_get_cache(key=coordinates)
if data is not None:
data = json.loads(data)
- data["cache"] = True
+ #data["cache"] = True
+ print("DEBUG - CACHE: TRUE")
+ print(data)
+ print(coordinates)
return data
else:
data = SnoParser.whois_fresh(coordinates)
- if data.get("code") == "Ok":
- data["cache"] = False
+ print("ELSE WHOIS_FRESH CALLED")
+ print(data)
+ print(coordinates)
+ if data.startswith("WHOIS"):
+ #data["cache"] = False
+ print("DEBUG - CACHE: FALSE")
data = json.dumps(data)
- state = self.whois_set_cache(key=coordinates, value=data)
+ state = SnoParser.whois_set_cache(key=coordinates, value=data)
+
+ print(data)
+ print(coordinates)
if state is True:
return json.loads(data)
+ else:
+ print("Data does not start with correct string")
+ print(data)
return data
@@ -132,14 +149,18 @@ class SnoParser(callbacks.Plugin):
username = couple.group(2)
host = couple.group(3)
#ip = couple.group(4)
- ip = '81.217.9.47'
+ ip = '::1'
realname = couple.group(5)
ip_seen = 0
nick_seen = 0
asn = 0
subnet = ''
- SnoParser.whois_run(coordinates=ip)
+# SnoParser.whois_run(coordinates=ip)
+ whoisout = SnoParser.whois_run(ip)
+# whoisout = SnoParser.whois_run(whoisout)
+# SnoParser.whois_run(ip)
+# whoisout = SnoParser.whois_run.coordinates
# try:
# #whois = IPWhois(ip)