nadzoring.network_base.connections module¶
Active network connections listing (netstat/ss equivalent).
- class nadzoring.network_base.connections.ConnectionEntry(protocol: str, local_address: str, remote_address: str, state: str, pid: str | None = None, process: str | None = None)[source]¶
Bases:
objectRepresents a single active network connection.
- __init__(protocol: str, local_address: str, remote_address: str, state: str, pid: str | None = None, process: str | None = None) None[source]¶
- local_address: str¶
- pid: str | None = None¶
- process: str | None = None¶
- protocol: str¶
- remote_address: str¶
- state: str¶
- nadzoring.network_base.connections._filter_entries(entries: list[ConnectionEntry], *, protocol: str, state_filter: str | None) list[ConnectionEntry][source]¶
Filter connection entries by protocol and state.
- Parameters:
entries – List of connection entries to filter.
protocol – Protocol filter - ‘tcp’, ‘udp’, or ‘all’.
state_filter – Optional state substring filter (case-insensitive).
- Returns:
Filtered list of ConnectionEntry objects.
- nadzoring.network_base.connections._get_linux_connections(*, protocol: str, state_filter: str | None, include_process: bool) list[ConnectionEntry][source]¶
Get active connections on Linux using ss.
- nadzoring.network_base.connections._get_windows_connections(*, protocol: str, state_filter: str | None) list[ConnectionEntry][source]¶
Get active connections on Windows using netstat.
- nadzoring.network_base.connections._parse_netstat_output(raw: str) list[ConnectionEntry][source]¶
Parse the output of the Windows ‘netstat -ano’ command.
- Parameters:
raw – Raw text output from netstat -ano.
- Returns:
List of parsed ConnectionEntry objects.
- nadzoring.network_base.connections._parse_ss_output(raw: str) list[ConnectionEntry][source]¶
Parse the output of the Linux ‘ss’ command.
- Parameters:
raw – Raw text output from ss command.
- Returns:
List of parsed ConnectionEntry objects.
- nadzoring.network_base.connections.get_connections(*, protocol: str = 'all', state_filter: str | None = None, include_process: bool = True) list[ConnectionEntry][source]¶
List active network connections on the current system.
On Linux, uses ‘ss’. On Windows, uses ‘netstat -ano’. Process information may require elevated permissions on some systems.
- Parameters:
protocol – Protocol to filter by - ‘tcp’, ‘udp’, or ‘all’. Defaults to ‘all’.
state_filter – Case-insensitive state substring filter, e.g. ‘LISTEN’ or ‘ESTABLISHED’. Defaults to None (no filter).
include_process – Whether to include PID/process name (may need root on Linux). Defaults to True.
- Returns:
List of ConnectionEntry objects, one per active connection.
Examples
>>> listening = get_connections(state_filter="LISTEN") >>> len(listening) > 0 True