Skip to content

model.netinfo

model.netinfo

ProcessInfo dataclass

Store process metadata for a socket record.

Source code in model/netinfo.py
 8
 9
10
11
12
13
14
15
16
@dataclass(frozen=True)
class ProcessInfo:
    """Store process metadata for a socket record."""

    status: str
    label: str
    name: str | None = None
    exe: str | None = None
    cmdline: list[str] | None = None

NetInfoBackend

Bases: Protocol

Backend interface for collecting socket records.

Source code in model/netinfo.py
19
20
21
22
23
class NetInfoBackend(Protocol):
    """Backend interface for collecting socket records."""

    def get_data(self) -> list[dict[str, Any]]:
        """Return connection records with socket and process fields."""

get_data()

Return connection records with socket and process fields.

Source code in model/netinfo.py
22
23
def get_data(self) -> list[dict[str, Any]]:
    """Return connection records with socket and process fields."""

NetInfo

Facade that selects the correct backend for the current OS.

Parameters:

Name Type Description Default
allowed_statuses set[str] | None

If set, include only TCP connections with a status in this set. Always include UDP sockets.

None
Source code in model/netinfo.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class NetInfo:
    """Facade that selects the correct backend for the current OS.

    Args:
        allowed_statuses:
            If set, include only TCP connections with a status in this set.
            Always include UDP sockets.
    """

    def __init__(self, allowed_statuses: set[str] | None = None) -> None:
        self.allowed_statuses = allowed_statuses
        self._backend = self._select_backend()

    def get_data(self) -> list[dict[str, Any]]:
        """Return connection records with socket and process fields."""
        return self._backend.get_data()

    def _select_backend(self) -> NetInfoBackend:
        system = platform.system()

        if system in {"Linux", "Windows"}:
            from .netinfo_psutil import PsutilNetInfo

            return PsutilNetInfo(allowed_statuses=self.allowed_statuses)

        raise NotImplementedError(f"NetInfo backend is not implemented for OS: {system}")

get_data()

Return connection records with socket and process fields.

Source code in model/netinfo.py
39
40
41
def get_data(self) -> list[dict[str, Any]]:
    """Return connection records with socket and process fields."""
    return self._backend.get_data()