在 windows 下如何使用 Python 获得网卡名字

2017-11-20 16:44:20 +08:00
 ttxxyy112233

在 python 下想用 scapy,里面 iface 需要网卡名字,通过函数 show_interfaces()可以得到如下:

INDEX IFACE
11 VMware Virtual Ethernet Adapter for VMnet0
13 Killer E2200 Gigabit Ethernet Controller

那么有没有办法直接得到网卡名字的 list?

5460 次点击
所在节点    Python
3 条回复
xpresslink
2017-11-22 15:37:52 +08:00
有个 WMI 包可以获取硬件信息
shamashii
2017-11-23 13:26:20 +08:00
ifaddr.get_adapters()
vincentfeng
2018-04-07 20:41:40 +08:00
def get_netcard():
netcard_info = []
info = psutil.net_if_addrs()
for k, v in info.items():
for item in v:
if item[0] == 2 and not item[1] == '127.0.0.1':
netcard_info.append(k)
return netcard_info

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/407966

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX