nadzoring.network_base.port_scanner module¶
TCP/UDP port scanning functionality with multi-threading support.
- class nadzoring.network_base.port_scanner.PortResult(port: int, state: Literal['open', 'closed', 'filtered', 'open|filtered'], service: str = 'unknown', banner: str | None = None, response_time: float | None = None)[source]¶
Bases:
objectResult of a single port scan.
- __init__(port: int, state: Literal['open', 'closed', 'filtered', 'open|filtered'], service: str = 'unknown', banner: str | None = None, response_time: float | None = None) None¶
- banner: str | None = None¶
- port: int¶
- response_time: float | None = None¶
- service: str = 'unknown'¶
- state: Literal['open', 'closed', 'filtered', 'open|filtered']¶
- class nadzoring.network_base.port_scanner.ScanConfig(targets: list[str], mode: Literal['fast', 'full', 'custom'] = 'fast', protocol: Literal['tcp', 'udp'] = 'tcp', custom_ports: list[int] | None = None, port_range: tuple[int, int] | None = None, timeout: float = 2.0, max_workers: int = 50, grab_banner: bool = True, progress_callback: Callable[[str, int, int], None] | None = None)[source]¶
Bases:
objectConfiguration for a port scan operation.
- __init__(targets: list[str], mode: Literal['fast', 'full', 'custom'] = 'fast', protocol: Literal['tcp', 'udp'] = 'tcp', custom_ports: list[int] | None = None, port_range: tuple[int, int] | None = None, timeout: float = 2.0, max_workers: int = 50, grab_banner: bool = True, progress_callback: Callable[[str, int, int], None] | None = None) None¶
- custom_ports: list[int] | None = None¶
- grab_banner: bool = True¶
- max_workers: int = 50¶
- mode: Literal['fast', 'full', 'custom'] = 'fast'¶
- port_range: tuple[int, int] | None = None¶
- progress_callback: Callable[[str, int, int], None] | None = None¶
- protocol: Literal['tcp', 'udp'] = 'tcp'¶
- targets: list[str]¶
- timeout: float = 2.0¶
- class nadzoring.network_base.port_scanner.ScanResult(target: str, target_ip: str, start_time: datetime, end_time: datetime, results: dict[int, ~nadzoring.network_base.port_scanner.PortResult]=<factory>)[source]¶
Bases:
objectComplete scan result for a single target.
- __init__(target: str, target_ip: str, start_time: datetime, end_time: datetime, results: dict[int, ~nadzoring.network_base.port_scanner.PortResult]=<factory>) None¶
- property duration: float¶
Calculate scan duration in seconds.
- end_time: datetime¶
- property open_ports: list[int]¶
Get list of open port numbers.
- results: dict[int, PortResult]¶
- start_time: datetime¶
- target: str¶
- target_ip: str¶
- nadzoring.network_base.port_scanner._grab_banner(sock: socket, target_ip: str, port: int) str | None[source]¶
Attempt to grab banner from open port.
- nadzoring.network_base.port_scanner._scan_target_ports(target_ip: str, ports: list[int], config: ScanConfig, target: str, total_targets: int) ScanResult[source]¶
Perform port scan on a single target.
- nadzoring.network_base.port_scanner._scan_tcp_port(target_ip: str, port: int, timeout: float, *, grab_banner: bool) tuple[int, PortResult][source]¶
Scan a single TCP port on a target.
- nadzoring.network_base.port_scanner._scan_udp_port(target_ip: str, port: int, timeout: float) tuple[int, PortResult][source]¶
Scan a single UDP port on a target.
- nadzoring.network_base.port_scanner.get_ports_from_mode(config: ScanConfig) list[int][source]¶
Generate list of ports to scan based on configuration mode.
- nadzoring.network_base.port_scanner.resolve_target(target: str) str | None[source]¶
Resolve hostname to IP address.
- nadzoring.network_base.port_scanner.scan_ports(config: ScanConfig) list[ScanResult][source]¶
Scan multiple targets for open ports.