Source code for config.ports

from typing import Dict, List


[docs] class PortConfig: """Конфигурация известных портов для сетевого анализа. Назначение: Предоставляет сопоставление распространённых портов с человекочитаемыми названиями сервисов для отображения в UI и логах. Поддерживает расширение пользовательским словарём. """ _DEFAULT_PORTS: Dict[int, str] = { 20: "FTP (Data)", 21: "FTP (Control)", 22: "SSH", 23: "Telnet", 25: "SMTP", 53: "DNS", 67: "DHCP (Server)", 68: "DHCP (Client)", 69: "TFTP", 80: "HTTP", 110: "POP3", 123: "NTP (Network Time Protocol)", 137: "NetBIOS Name Service", 138: "NetBIOS Datagram Service", 139: "NetBIOS Session Service", 143: "IMAP", 161: "SNMP", 162: "SNMP Trap", 179: "BGP (Border Gateway Protocol)", 443: "HTTPS", 445: "SMB (Microsoft-DS)", 465: "SMTPS", 514: "Syslog (UDP)", 515: "LPD (Printer)", 587: "SMTP Submission", 631: "IPP (Printing)", 993: "IMAPS", 995: "POP3S", # --- Базы данных --- 1433: "Microsoft SQL Server", 1521: "Oracle DB", 3306: "MySQL/MariaDB", 5432: "PostgreSQL", 6379: "Redis", 27017: "MongoDB", # --- VPN и удалённый доступ --- 1723: "PPTP VPN", 1701: "L2TP", 500: "IPSec", 4500: "IPSec NAT-T", 1194: "OpenVPN", 3389: "RDP (Remote Desktop Protocol)", 5900: "VNC", # --- Прокси / Веб --- 1080: "SOCKS Proxy", 8000: "HTTP-Alt", 8080: "HTTP Proxy", 8443: "HTTPS-Alt", # --- DevOps / Monitoring / Tools --- 9000: "SonarQube / PHP-FPM", 9100: "Prometheus Node Exporter", 9200: "Elasticsearch HTTP", 9300: "Elasticsearch Cluster", 11211: "Memcached", # --- Прочее --- 6667: "IRC", 4000: "ICQ / Custom apps", 25565: "Minecraft Server", 53: "DNS (UDP & TCP)", } def __init__(self, custom_ports: Dict[int, str] = None): """ Инициализирует конфигурацию портов. Args: custom_ports: Пользовательский словарь портов для добавления или переопределения. """ self._ports = self._DEFAULT_PORTS.copy() if custom_ports: self._ports.update(custom_ports)
[docs] def get_port_name(self, port: int) -> str: """ Возвращает название сервиса для указанного порта. Args: port: Номер порта. Returns: Название сервиса или строка вида 'Port-<port>'. """ return self._ports.get(port, f"Port-{port}")
[docs] def get_ports(self) -> List[int]: """ Возвращает список всех номеров портов. Returns: Список номеров портов. """ return list(self._ports.keys())
port_config = PortConfig()