diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2021-06-06 01:37:50 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2021-06-06 01:37:50 +0300 |
commit | 7c1494cd502e1a99f96f27b12ddf23a84de188b5 (patch) | |
tree | 0a236d75fa14ed9176d8013a0b4c00d8ea64cb86 /lib/results.py | |
parent | fe07ea26f41be1eda6f8cccc591a5165dd3fb135 (diff) |
refactor code, add manual-scan script
Diffstat (limited to 'lib/results.py')
-rw-r--r-- | lib/results.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/results.py b/lib/results.py new file mode 100644 index 0000000..1565c4b --- /dev/null +++ b/lib/results.py @@ -0,0 +1,52 @@ +from threading import Lock +from lib.util import Colored +from lib.scanner import PortState +from ch1p import telegram_notify + + +class Results: + def __init__(self): + self.warnings = [] + self.mutex = Lock() + + def add(self, worker): + host = worker.get_host() + with self.mutex: + if not worker.done: + print(f'{Colored.RED}{worker.name}: scanning failed{Colored.END}') + return + + if worker.name != host: + print(f'{worker.name} ({host}):') + else: + print(f'{host}:') + + opened = [] + results = worker.get_results() + for port, state in results: + if state != PortState.OPEN: + continue + + opened.append(port) + if not worker.is_expected(port): + self.warnings.append(f'<b>{worker.name}</b> ({host}): port {port} is open') + print(f' {Colored.RED}{port} opened{Colored.END}') + else: + print(f' {Colored.GREEN}{port} opened{Colored.END}') + + if worker.opened: + for port in worker.opened: + if port not in opened: + self.warnings.append( + f'<b>{worker.name}</b> ({host}): port {port} is NOT open') + print(f' {Colored.RED}{port} not opened{Colored.END}') + print() + + def has_warnings(self): + return len(self.warnings) > 0 + + def notify(self, chat_id=None, token=None): + text = '<b>❗️Attention!</b>\n\n' + text += '\n'.join(self.warnings) + + telegram_notify(text, parse_mode='html', chat_id=chat_id, token=token) |