diff options
| author | Georg | 2021-08-26 13:51:26 +0200 |
|---|---|---|
| committer | Georg | 2021-08-26 13:51:26 +0200 |
| commit | 415d5df94ce6ed024302852dd3fca6bc07dcaf99 (patch) | |
| tree | 1c84180901a8e4616524265614d85ce032a9de35 /plugin.py | |
| parent | f796a296911f71edc80e9e24e33413ce91af9003 (diff) | |
| download | snoparser-415d5df94ce6ed024302852dd3fca6bc07dcaf99.tar.gz snoparser-415d5df94ce6ed024302852dd3fca6bc07dcaf99.tar.bz2 snoparser-415d5df94ce6ed024302852dd3fca6bc07dcaf99.zip | |
First prettifications of Redis cached whois
Signed-off-by: Georg <georg@lysergic.dev>
Diffstat (limited to 'plugin.py')
| -rw-r--r-- | plugin.py | 56 |
1 files changed, 19 insertions, 37 deletions
@@ -56,11 +56,12 @@ class SnoParser(callbacks.Plugin): def redis_connect() -> redis.client.Redis: try: redis_client = redis.Redis( - host="localhost", - port=6378, - #password="test", - db=0, - socket_timeout=5, + host = .registryValue('whois.redis.host'), + port = self.registryValue('whois.redis.port'), + password = self.registryValue('whois.redis.password'), + username = self.registryValue('whois.redis.username'), + db = self.registryValue('whois.redis.db'), + socket_timeout = self.registryValue('whois.redis.timeout') ) ping = redis_client.ping() if ping is True: @@ -70,12 +71,12 @@ class SnoParser(callbacks.Plugin): redis_client = redis_connect() - def whois_fresh(coordinates: str) -> dict: + def whois_fresh(sourceip: str) -> dict: """Data from cache.""" asn = 0 subnet = '' try: - whois = IPWhois(coordinates) + whois = IPWhois(sourceip) whoisres = whois.lookup_rdap(depth=1,retry_count=0) results = whoisres print(results) @@ -86,10 +87,6 @@ class SnoParser(callbacks.Plugin): except ipwhois.exceptions.IPDefinedError: whoisout = 'RFC 4291 (Local)' -# rr = f"{results}" -# response = rr -# return response.json() -# response = results response = whoisout return response @@ -105,28 +102,30 @@ class SnoParser(callbacks.Plugin): 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) + def whois_run(sourceip: str) -> dict: + """Whois query router.""" + + data = SnoParser.whois_get_cache(key=sourceip) if data is not None: data = json.loads(data) #data["cache"] = True print("DEBUG - CACHE: TRUE") print(data) - print(coordinates) + print(sourceip) return data else: - data = SnoParser.whois_fresh(coordinates) - print("ELSE WHOIS_FRESH CALLED") + data = SnoParser.whois_fresh(sourceip) + print("DEBUG - ELSE WHOIS_FRESH CALLED") print(data) - print(coordinates) + print(sourceip) if data.startswith("WHOIS"): #data["cache"] = False print("DEBUG - CACHE: FALSE") data = json.dumps(data) - state = SnoParser.whois_set_cache(key=coordinates, value=data) + state = SnoParser.whois_set_cache(key=sourceip, value=data) print(data) - print(coordinates) + print(sourceip) if state is True: return json.loads(data) @@ -149,31 +148,14 @@ class SnoParser(callbacks.Plugin): username = couple.group(2) host = couple.group(3) #ip = couple.group(4) - ip = '::1' + ip = '2a03:4000:55:d20::' realname = couple.group(5) ip_seen = 0 nick_seen = 0 asn = 0 subnet = '' -# 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) -# #whoisres = whois.lookup_rdap(depth=1,retry_count=0) -# #results = whoisres -# whoisres = data -# 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)' DictFromSnotice = {'notice': 'connect', 'nickname': nickname, 'username': username, 'host': host, 'ip': ip, 'realname': realname, 'ipCount': ip_seen, 'nickCount': nick_seen} #repl = f"\x02\x1FNOTICE: {DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" repl = f"\x02\x1F{DictFromSnotice['notice']} \x0F\x11\x0303==>>\x0F \x02Nick:\x0F {DictFromSnotice['nickname']} \x02Username:\x0F {DictFromSnotice['username']} \x02Hostname:\x0F {DictFromSnotice['host']} \x02IP:\x0F {DictFromSnotice['ip']} {whoisout} \x02Realname:\x0F {DictFromSnotice['realname']} \x02IPcount:\x0F {DictFromSnotice['ipCount']} \x02NickCount:\x0F {DictFromSnotice['nickCount']}" |
