86 views
Как посмотреть, какие есть сетевые интерфейсы?
Asked at
AI answer
In Python, you can get interface names using the standard library:
import socket
interfaces = socket.if_nameindex()
print(interfaces) # for example: [(1, 'lo'), (2, 'eth0')]
If you need IP addresses and other details, the third-party package psutil is convenient:
import psutil
for name, addresses in psutil.net_if_addrs().items():
print(name, [addr.address for addr in addresses])
To view interfaces from the command line on Linux, use ip link or ip addr.