IRCP- information gathering tool for irc servers |
git clone git://git.acid.vegas/IRCP.git |
Log | Files | Refs | Archive | README | LICENSE |
parser.py (1599B)
1 #!/usr/bin/env python 2 # ircp logs parser - developed by acidvegas in python (https://git.acid.vegas/ircp) 3 4 import json 5 import os 6 import sys 7 8 def parse(option, data, raw=True): 9 if not raw: 10 data = ' '.join(data.split()[3:]) 11 if data[:1] == ':': 12 data = data[1:] 13 if type(data) == bool: 14 data = str(data) 15 print(data.replace(option, f'\033[31m{option}\033[0m')) 16 return data 17 18 # Main 19 if len(sys.argv) >= 2: 20 option = sys.argv[1] 21 raw = True 22 search = False 23 if len(sys.argv) == 3: 24 if sys.argv[2] == 'clean': 25 raw = False 26 elif sys.argv[2] == 'search': 27 search = True 28 logs = os.listdir('logs') 29 found = list() 30 for log in logs: 31 with open('logs/'+log) as logfile: 32 try: 33 data = json.loads(logfile.read()) 34 except: 35 print('error: failed to load ' + log) 36 break 37 if option in data: 38 data = data[option] 39 if type(data) == str: 40 found.append(parse(option, data, raw)) 41 elif type(data) == list: 42 for item in data: 43 found.append(parse(option, item, raw)) 44 elif search: 45 for item in data: 46 _data = data[item] 47 if type(_data) == str and option in _data: 48 found.append(parse(option, item, raw)) 49 elif type(_data) == list: 50 for _item in _data: 51 if option in _item: 52 found.append(parse(option, _item, raw)) 53 if found: 54 print(f'\nfound {len(found)} results in {len(logs)} logs') 55 else: 56 print('usage: python parser.py <field> [clean]\n') 57 print(' <field> may be any item in the snapshots (001, NOTICE, 464, etc) or a string to search') 58 print(' [clean] may be optionally used to display a cleaner output')