How to get meaningful network interface names instead of GUIDs with netifaces under Windows?

前端 未结 6 799
天涯浪人
天涯浪人 2020-12-05 18:52

I use the netifaces module.

import netifaces
print netifaces.interfaces()

but this shows the result below:

 [\         


        
6条回答
  •  鱼传尺愫
    2020-12-05 19:31

    We can also use Windows WMI:

    import wmi
    
    c = wmi.WMI()
    qry = "select Name from Win32_NetworkAdapter where NetEnabled=True and NetConnectionStatus=2"
    
    lst = [o.Name for o in c.query(qry)]
    print(lst)
    

    yields on my machine:

    ['Realtek PCIe GBE Family Controller', 'VMware Virtual Ethernet Adapter for VMnet1', 'VMware Virtual Ethernet Adapter for VMnet8', 'VirtualBox Host-Only Ethernet Adapter']
    

    MSDN: Win32_NetworkAdapter class

提交回复
热议问题