Python 获取openwrt中的物理接口列表

Python 获取openwrt中的物理接口列表,python,networking,network-programming,sh,openwrt,Python,Networking,Network Programming,Sh,Openwrt,如何在openwrt中获得所有物理接口,我尝试了ls-l/sys/class/net/,但这不是正确的信息 lrwxrwxrwx 1 root root 0 Mar 21 10:26 eth0 -> ../../devices/virtual/net/eth0 lrwxrwxrwx 1 root root 0 Mar 21 10:26 eth1 -> ../../devices/virtual/net/eth

如何在openwrt中获得所有物理接口,我尝试了ls-l/sys/class/net/,但这不是正确的信息

lrwxrwxrwx    1 root     root             0 Mar 21 10:26 eth0 -> ../../devices/virtual/net/eth0
lrwxrwxrwx    1 root     root             0 Mar 21 10:26 eth1 -> ../../devices/virtual/net/eth1
lrwxrwxrwx    1 root     root             0 Mar 21 10:26 tun0 -> ../../devices/virtual/net/tun0
lrwxrwxrwx    1 root     root             0 Mar 22 09:50 wlan0 -> ../../devices/pci0000:01/0000:01:00.0/net/wlan0
lrwxrwxrwx    1 root     root             0 Mar 22 09:50 wlan0-1 -> ../../devices/pci0000:01/0000:01:00.0/net/wlan0-1
实际上eth0和eth1是物理的,wlan0-1也是逻辑的。但是结果显示不同


有人能提出更好的方法吗?

您好,您可以使用python scapy获取接口列表

from scapy.all import *
print(get_windows_if_list())

为什么不
ifconfig
ifconfig
将返回所有接口,但我看不到任何说明接口是物理接口还是虚拟接口的信息。只要虚拟接口是OSI第3层,然后,您可以将
ip link show
返回的MAC地址与
ip addr show
列出的绑定到第3层接口的MAC地址进行比较。