nadzoring.network_base package

Submodules

nadzoring.network_base.geolocation_ip module

nadzoring.network_base.geolocation_ip.geo_ip(ip: str) dict[str, str][source]

A function for getting coordinates based on an external IP address.

Performs a request to the service, which transmits the address. In response, it receives JSON with coordinates and more (the rest of the data is not returned from the function). However, if necessary, it can be expanded.

Parameters:

ip (str) – ip address

Returns:

dict with lat and lon or None

Return type:

dict[str, str] | None

nadzoring.network_base.ipv4_local_cli module

Script for obtaining the local IP address using standard OS utilities. Supports Linux and Windows operating systems by parsing command outputs. No additional library installations required.

nadzoring.network_base.ipv4_local_cli._get_linux_ip() str | None[source]

Retrieves local IPv4 address on Linux systems by parsing ‘ip’ command output.

Returns:

Local IPv4 address if found, None otherwise.

Return type:

str | None

nadzoring.network_base.ipv4_local_cli._get_windows_ip() str | None[source]

Retrieves local IPv4 address on Windows systems using wmic command.

Returns:

Local IPv4 address if found, None otherwise.

Return type:

str | None

nadzoring.network_base.ipv4_local_cli._parse_windows_network_config(config_lines: list) str | None[source]

Parses Windows network configuration output to extract IPv4 address.

Parameters:

config_lines – List of configuration lines from wmic command.

Returns:

Local IPv4 address if found, None otherwise.

Return type:

str | None

nadzoring.network_base.ipv4_local_cli.get_local_ipv4() str | None[source]

Main function to get local IPv4 address based on the operating system.

Returns:

Local IPv4 address if found, None otherwise.

Return type:

str | None

Raises:

NotImplementedError – If running on an unsupported operating system.

nadzoring.network_base.network_params module

The script returns the result of parsing the execution of standard Linux and Windows commands. A dictionary with basic parameters of the default network interface is returned. The basic parameters include: the name of the network interface, local v4 and v6 ip addresses, the default gateway address, and the mac address of the network interface.

On some linux machines, the net-tools package must be installed, because the route command doesn’t work without it (example: Ubuntu): sudo apt install net-tools

In addition to the above package, no third-party libraries are required for the script to work.

nadzoring.network_base.network_params._create_empty_network_info() dict[str, None][source]

Create empty network information dictionary.

nadzoring.network_base.network_params._extract_interface_details(interface_parts: list[str]) dict[str, str | None][source]

Extract detailed information from an interface configuration.

nadzoring.network_base.network_params._find_enabled_interface(config_blocks: list[str]) list[str] | None[source]

Find the first enabled network interface.

nadzoring.network_base.network_params._get_linux_gateway() str | None[source]

Get default gateway on Linux.

nadzoring.network_base.network_params._get_linux_interface_info() dict[str, str | None][source]

Extract interface name and IP addresses on Linux.

nadzoring.network_base.network_params._get_linux_mac_address(interface_name: str | None) str | None[source]

Get MAC address for a specific interface on Linux.

nadzoring.network_base.network_params._get_linux_network_info() dict[str, str | None][source]

Get network information for Linux systems.

nadzoring.network_base.network_params._get_windows_network_info() dict[str, str | None][source]

Get network information for Windows systems.

nadzoring.network_base.network_params._parse_windows_network_configs() list[str][source]

Parse Windows network configuration output.

nadzoring.network_base.network_params.network_param() dict[str, str | None] | None[source]

Get basic network parameters for the current system.

Returns:

Dictionary with network interface information or None if OS not supported.

nadzoring.network_base.network_params.public_ip() str[source]

Getting an external IP address by accessing the service api: https://api.ipify.org/

Returns:

public IP

Return type:

str

nadzoring.network_base.ping_address module

This script performs a standard ping of a specific address or domain name. It works in the same way as the standard OS module. It does not ping addresses that are protected from pinging, such as “codeby.net”. It can be used for a shallow check of addresses.

nadzoring.network_base.ping_address.ping_addr(addr: str) bool[source]

A normal ping of a specific ip address or domain.

The original function returns if the domain or address is unavailable None. If successful, the time for which ping is being performed. This function returns Boolean values in the case of success or failure.

Parameters:

addr (str) – address

Returns:

is pinged

Return type:

bool

nadzoring.network_base.router_ip module

Returns the default router(gateway) ip address on Linux and Windows machines.

On some Linux machines, it requires the net-tools package to be installed, as the route command does not work without it (example: Ubuntu):

$ sudo apt install net-tools

nadzoring.network_base.router_ip.check_ipv4(hostname: str) str[source]

Checking whether the received value is an ip address.

If the received value is not an ip address, an exception is thrown and the received value is passed to the function to obtain the address from the domain name. If the check is successful, the address is returned from the function.

Parameters:

ip (str) – hostname address

Returns:

hostname

Return type:

str

nadzoring.network_base.router_ip.check_ipv6(hostname: str) str[source]

Checking whether the received value is an ip address.

If the received value is not an ip address, an exception is thrown and the received value is passed to the function to obtain the address from the domain name. If the check is successful, the address is returned from the function.

Parameters:

ip (str) – hostname address

Returns:

hostname

Return type:

str

nadzoring.network_base.router_ip.get_ip_from_host(hostname: str) str[source]

Attempts to retrieve an IP address from a domain name.

If unsuccessful, returns the value passed to the function.

Parameters:

hostname (str) – hostname address

Returns:

host

Return type:

str

nadzoring.network_base.router_ip.router_ip(*, ipv6: bool = False) str | None[source]

The OS version is determined, then, using the subprocess library, a command specific to each OS is executed to determine the router address.

Then the received value is sent to check if it matches the address. If the received address is IPv4, it is returned from the function. If the address is a domain name, and there may be such cases, the received name is passed to the function where the attempt is performed. getting an ip address by domain name. For example, if the system uses pfsence.

Parameters:

ipv6 (bool, optional) – use IPv6 instead of IPv4. Defaults to False.

Returns:

ip route result or None

Return type:

str | None

nadzoring.network_base.service_on_port module

nadzoring.network_base.service_on_port.get_service_on_port(port: int) str[source]

Module contents