Python 3.3+socketfunction
socket.if_nameindex()
network interfaces
Returns the machine's network interfaces as (index, name) pairs: (1, 'lo'), (2, 'eth0').
Syntax
socket.if_nameindex() -> list[tuple[int, str]]
The list and the names depend entirely on the machine, so tests never hard-code them. On Windows the names are special, like 'ethernet_32770', not the friendly name such as 'vEthernet (nat)' from the control panel. No addresses are returned, only indexes and names; the index is used, for example, as the scope_id of link-local IPv6 addresses.
Examples
import socket
for index, name in socket.if_nameindex():
print(index, name) # → ? 1 lo / 2 eth0
print(isinstance(socket.if_nameindex(), list)) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy