From 308f9b3048aca2a14a5cf287a0a925303bcde910 Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Wed, 12 Aug 2026 13:10:20 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D1=86=D0=B5=D0=BB=D0=B5=D0=B2=D1=8B=D1=85=20IP=20?= =?UTF-8?q?=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=87=D0=B0=D1=81=D1=82=D0=BD=D1=8B=D1=85/=D0=B7=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=B7=D0=B5=D1=80=D0=B2=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=B0?= =?UTF-8?q?=D0=B7=D0=BE=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/netsleuth/cli.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/netsleuth/cli.py b/src/netsleuth/cli.py index 9efbccd..a185c70 100644 --- a/src/netsleuth/cli.py +++ b/src/netsleuth/cli.py @@ -129,8 +129,69 @@ def format_siblings( return None, None +def _is_private_or_reserved_ip(ip: str) -> bool: + """Проверяет, является ли IP адрес частным или зарезервированным. + + Args: + ip: IP адрес для проверки + + Returns: + True если IP частный/зарезервированный, False иначе + """ + forbidden_prefixes = [ + "127.", # localhost + "0.", # current network + "10.", # private class A + "192.168.", # private class C + "172.16.", # private class B (start) + "172.17.", + "172.18.", + "172.19.", + "172.20.", + "172.21.", + "172.22.", + "172.23.", + "172.24.", + "172.25.", + "172.26.", + "172.27.", + "172.28.", + "172.29.", + "172.30.", + "172.31.", + "169.254.", # link-local + "224.", # multicast + "240.", # reserved + "::1", # IPv6 localhost + "fe80:", # IPv6 link-local + "fc00:", # IPv6 unique local + "fd00:", # IPv6 unique local + ] + return any(ip.startswith(prefix) for prefix in forbidden_prefixes) + + def parse_target(value: str) -> tuple[str, str]: + """Парсит и валидирует целевой хост для диагностики. + + Args: + value: Строка с целью (IP, домен, ASN) + + Returns: + Кортеж (тип_цели, значение) + + Raises: + typer.BadParameter: Если цель невалидна или запрещена + """ text = value.strip() + + # Проверка на частные/зарезервированные IP + if all(part.isdigit() for part in text.split(".")) and text.count(".") == 3: + if _is_private_or_reserved_ip(text): + raise typer.BadParameter( + f"Target IP {text} is private or reserved; " + "please use a public IP address or domain name" + ) + if text.upper().startswith("AS") and text[2:].isdigit(): return "asn", text.upper() if text.isdigit(): @@ -138,6 +199,12 @@ def parse_target(value: str) -> tuple[str, str]: if all(part.isdigit() for part in text.split(".")) and text.count(".") == 3: return "ip", text if ":" in text: + # IPv6 проверка + if _is_private_or_reserved_ip(text): + raise typer.BadParameter( + f"Target IPv6 {text} is private or reserved; " + "please use a public IPv6 address" + ) return "ip", text return "domain", text