This commit is contained in:
Dmitry Belyaev 2025-03-13 12:07:25 +03:00
parent f59b7ab639
commit a6447c9208
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

@ -4,7 +4,6 @@ import sys
import pathlib
from typing import NamedTuple, TypeAlias
datepattern = re.compile(r"(?P<date>\d{4}(-\d{2}){2})\s")
pattern = re.compile(
r"(?P<date>\d{4}(-\d{2}){2})\s(?P<time>\d{2}(:\d{2}){2})\s(?P<IP>\d{1,3}(\.\d{1,3}){3}):\d+\s\[(?P<name>\w+)\]\sPeer\sConnection\sInitiated"
)
@ -30,10 +29,8 @@ def log_lines(filepath: pathlib.Path):
yield line
def filter_log_lines_for_date(filepath: pathlib.Path, date: str):
return filter(
lambda line: datepattern.match(line).group("date") == date, log_lines(filepath)
)
def filter_log_lines_for_date(lines, date: str):
return filter(lambda line: line.startswith(date + " "), lines)
def parse_date_time(date: str, time: str) -> datetime.datetime:
@ -110,7 +107,7 @@ def print_fast_repeats(connmap: ConnectionMap, limit_for_one=10):
for name, infos in connmap.items():
print(f"- {name}:")
for n, info in enumerate(
reversed(sorted(infos, key=lambda info: info.datetime)), 1
sorted(infos, key=lambda info: info.datetime, reverse=True), 1
):
print(f" {n:2}. {info.ip}: {info.datetime}")
if n >= limit_for_one:
@ -125,7 +122,7 @@ def main():
date = datetime.date.today().strftime("%Y-%m-%d")
log_file = pathlib.Path(sys.argv[1])
lines = log_lines(log_file)
lines = filter_log_lines_for_date(pathlib.Path(log_file), date)
lines = filter_log_lines_for_date(lines, date)
connmap = get_conn_map(lines)
multiple_ips = find_names_with_multiple_ips(connmap)
fast_repeats = find_fast_repeats(connmap, datetime.timedelta(minutes=3), 10)