nadzoring.network_base.route_table module¶
System routing table retrieval and parsing.
- class nadzoring.network_base.route_table.RouteEntry(destination: str, gateway: str, netmask: str | None, interface: str | None, metric: str | None, flags: str | None)[source]¶
Bases:
objectRepresents a single entry in the system routing table.
- __init__(destination: str, gateway: str, netmask: str | None, interface: str | None, metric: str | None, flags: str | None) None[source]¶
- destination: str¶
- flags: str | None¶
- gateway: str¶
- interface: str | None¶
- metric: str | None¶
- netmask: str | None¶
- nadzoring.network_base.route_table._get_linux_routes() list[RouteEntry][source]¶
Retrieve routing table on Linux using ‘ip route’.
- nadzoring.network_base.route_table._get_windows_routes() list[RouteEntry][source]¶
Retrieve routing table on Windows using ‘route PRINT’.
- nadzoring.network_base.route_table._parse_linux_ip_route(raw: str) list[RouteEntry][source]¶
Parse the output of ‘ip route’ on Linux.
- Each line is of the form:
<destination> [via <gateway>] dev <iface> [metric <n>] …
- Parameters:
raw – Raw text output from ip route.
- Returns:
List of RouteEntry objects.
- nadzoring.network_base.route_table._parse_windows_route_print(raw: str) list[RouteEntry][source]¶
Parse the output of ‘route PRINT’ on Windows.
Extracts IPv4 routes from the Active Routes section.
- Parameters:
raw – Raw text output from route PRINT.
- Returns:
List of RouteEntry objects.
- nadzoring.network_base.route_table.get_route_table() list[RouteEntry][source]¶
Retrieve the system’s IP routing table.
Uses ‘ip route’ on Linux and ‘route PRINT’ on Windows to fetch the current routing table and returns it as structured data.
- Returns:
List of RouteEntry objects representing all routing table entries, or an empty list if the OS is unsupported or the command fails.
Examples
>>> routes = get_route_table() >>> any(r.destination == "default" for r in routes) True