From 7c1494cd502e1a99f96f27b12ddf23a84de188b5 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 6 Jun 2021 01:37:50 +0300 Subject: refactor code, add manual-scan script --- lib/results.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/results.py (limited to 'lib/results.py') 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'{worker.name} ({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'{worker.name} ({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 = '❗️Attention!\n\n' + text += '\n'.join(self.warnings) + + telegram_notify(text, parse_mode='html', chat_id=chat_id, token=token) -- cgit v1.2.3