-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathozer.py
More file actions
executable file
·45 lines (43 loc) · 1.35 KB
/
ozer.py
File metadata and controls
executable file
·45 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/python3
import sys, re
import yaml
with open("/usr/bin/config.yaml", "r") as config:
try:
config = yaml.safe_load(config)
except yaml.YAMLError as exc:
config = None
print(exc)
CSI = "\x1B["
COLORS = {
'aqua': '36',
'blue': '34',
'red': '31',
'white': '37',
'green': '32',
'yellow': '33',
'pink': '35'
}
KEYWORDS = ['ip']
if __name__ == "__main__":
if config is None:
print('No config detected')
exit()
for line in sys.stdin:
l = line.lower()
if 'ip' in config:
pat = re.compile("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
IPs = pat.findall(l)
if IPs is not None:
for ip in IPs:
line = line.replace(ip, f'{CSI}{COLORS["yellow"]};40m{ip}{CSI}0m')
for key in config.keys():
if key not in KEYWORDS:
for item in config[key]['words']:
try:
compiled = re.compile(re.escape(str(item)), re.IGNORECASE)
line = compiled.sub(f'{CSI}{COLORS[config[key]["color"]]};40m{item}{CSI}0m', line)
except Exception as ex:
print("==========")
print(item, line)
print(f'An error happened: {str(ex)}')
print(line.rstrip("\n"))