network module

Classes for network operations.

Main classes

class ctlbase.network.NetworkManager(commandExecutor)

A manager for the local network.

It requires an ip binary on the host machine. On Debian-based syetems, it can be installed with sudo apt install iproute2.

In future releases, the implementation might switch to psutil.

__init__(commandExecutor)

Creates an network manager with a specific configuration.

Parameters:

commandExecutor (CommandExecutor) – The command executor to use for network-related commands like ip.

async getLocalIp(interface=None)

Determines the IPv4 and IPv6 address(es) of the localhost.

Parameters:

interface (str | None) – The logical name of the network interface from which to obtain the IP address(es), e.g. eth0. None to obtaim the IP addresses of all network interfaces.

Returns:

A sequence of IP addresses, possibly with only one element.

Return type:

list[str] | tuple[str]

async getLocalIp4(interface=None)

Determines the IPv4 address(es) of the localhost.

Parameters:

interface (str | None) – The logical name of the network interface from which to obtain the IP address(es), e.g. eth0. None to obtaim the IP addresses of all network interfaces.

Returns:

A sequence of IP addresses, possibly with only one element.

Return type:

list[str] | tuple[str]

async getLocalIp6(interface=None)

Determines the IPv6 address(es) of the localhost.

Parameters:

interface (str | None) – The logical name of the network interface from which to obtain the IP address(es), e.g. eth0. None to obtaim the IP addresses of all network interfaces.

Returns:

A sequence of IP addresses, possibly with only one element.

Return type:

list[str] | tuple[str]

async isLocalIp(ipAddress, interface=None)

Checks whether a specific IP address belongs to the localhost.

Parameters:
  • ipAddress (str | list | tuple) – One or more IPV4 or IPv6 addresses to be checked.

  • interface (str | None) – The logical name of the network interface from which to obtain the local IP address(es). None to obtain the IP addresses of all network interfaces.

Returns:

True if the given IP address(es) belong to the localhost, i.e. the host on which the process is running. False otherwise.

Return type:

bool