esptest.network.netif module

esptest.network.netif.get_interfaces()[source]

Get all network interfaces names.

Returns:

interface names

Return type:

List[str]

esptest.network.netif.get_all_ips_from_interface(interface, family=AddressFamily.AF_INET, prefix='')[source]

Get the IP address from network interface name.

Parameters:
  • interface (str) – specify network interface name

  • family (str, optional) – address family. Defaults to AF_INET.

  • prefix (str, optional) – filter ip address by prefix. Defaults to ‘’.

Raises:

ValueError – Can not get IP address

Returns:

IP addresses from the interface

Return type:

List[str]

esptest.network.netif.get_ip4_from_interface(interface='')[source]

Get the IPv4 address from network interface name.

Parameters:

interface (str, optional) – specify network interface name

Returns:

The most preferred IP address

Return type:

str

esptest.network.netif.get_ip6_from_interface(interface='', prefix='')[source]

Get the IPv6 address from network interface name.

Parameters:
  • interface (str, optional) – specify network interface name

  • prefix (str, optional) – filter ip address by prefix. Defaults to ‘’.

Returns:

The most preferred IPv6 address

Return type:

str

esptest.network.netif.get_local_ip4(to_addr='')[source]

Get the local IP (v4) that most likely to be able to connect to a remote IP or the Internet.

Depends on the routing table settings of this machine, usually returns the highest priority IP in the routing table.

Parameters:

to_addr (str, optional) – Try to get an IP that connect to this remote. Defaults to ‘8.8.8.8’(Internet).

Returns:

local IP address

Return type:

str

esptest.network.netif.ip_in_network(ip, network)[source]

Check the IP (v4/v6) address is in the network with given mask. Using ipaddress module: https://docs.python.org/3/library/ipaddress.html#module-ipaddress

Parameters:
  • ip (str) – IP address, eg: 192.168.1.2

  • subnet (str) – network, eg: 192.168.1.0/24 or 192.168.1.0/255.255.255.0

  • network (str)

Returns:

True if the IP address is in the network

Return type:

bool

esptest.network.netif.guess_local_ip6(to_addr, interface='')[source]

Guess ipv6 address by given remote ipv6.

Parameters:
  • to_addr (str) – target ip6 address that you want to establish a connection.

  • interface (str, optional) – specify local net interface. Defaults to ‘’.

Yields:

Iterator[str] – possible IP addresses (eg: fe80::2%eth0) that may connect to the given to_addr.

Return type:

Iterator[str]

esptest.network.netif.get_mac_by_interface(interface)[source]

Get hardware mac address from network interface name.

Parameters:

interface (str) – net interface name

Returns:

mac address (lower case)

Return type:

str

esptest.network.netif.get_interface_by_mac(mac_addr)[source]

Get network interface name by given mac address.

Parameters:

mac_addr (str) – hardware mac address.

Returns:

network interface name

Return type:

str