IRCP

- information gathering tool for irc servers
git clone git://git.acid.vegas/IRCP.git
Log | Files | Refs | Archive | README | LICENSE

commit bc3ccac030420c6fc7d6d145dc0db14fdb154782
parent 36570ea341b9ad279543adba43006f0d14031127
Author: acidvegas <acid.vegas@acid.vegas>
Date: Tue, 30 May 2023 03:10:29 -0400

Added the ability to search for strings with hilighting in the results using ANSI colors

Diffstat:
Mparser.py | 21+++++++++++++++++----

1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/parser.py b/parser.py
@@ -5,12 +5,12 @@ import json
 import os
 import sys
 
-def parse(data, raw=True):
+def parse(option, data, raw=True):
 	if not raw:
 		data = ' '.join(line.split()[3:])
 		if data[:1] == ':':
 			data = data[1:]
-	print(data)
+	print(data.replace(option, f'\033[31m{option}\033[0m'))
 	return data
 
 # Main
@@ -24,7 +24,11 @@ if len(sys.argv) >= 2:
 	found = list()
 	for log in logs:
 		with open('logs/'+log) as logfile:
-			data = json.loads(logfile.read())
+			try:
+				data = json.loads(logfile.read())
+			except:
+				print('error: failed to load ' + log)
+				break
 			if option in data:
 				data = data[option]
 				if type(data) == str:
@@ -32,9 +36,18 @@ if len(sys.argv) >= 2:
 				elif type(data) == list:
 					for item in data:
 						found.append(parse(item, raw))
+			else:
+				for item in data:
+					_data = data[item]
+					if type(_data) == str and option in _data:
+						found.append(parse(option, item, raw))
+					elif type(_data) == list:
+						for _item in _data:
+							if option in _item:
+								found.append(parse(option, _item, raw))
 	if found:
 		print(f'\nfound {len(found)} results in {len(logs)} logs')
 else:
 	print('usage: python parser.py <field> [clean]\n')
-	print('       <field> may be any item in the snapshots (001, NOTICE, 464, etc)')
+	print('       <field> may be any item in the snapshots (001, NOTICE, 464, etc) or a string to search')
 	print('       [clean] may be optionally used to display a cleaner output')
 \ No newline at end of file