bpod_core.misc.get_local_ipv4

bpod_core.misc.get_local_ipv4() str

Determine the primary local IPv4 address of the machine.

This function attempts to determine the IPv4 address of the local machine that would be used for an outbound connection to the internet. It does this by creating a UDP socket and connecting to a known public IP address (Google DNS at 8.8.8.8). No data is sent, but the OS uses the routing table to select the appropriate local interface.

Returns:

The local IPv4 address as a string. If the network is unreachable or unavailable, returns the loopback address 127.0.0.1.

Return type:

str

Raises:

OSError – If an unexpected socket error occurs during interface detection.