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

前端 未结 6 804
天涯浪人
天涯浪人 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:30

    If you know the IP Address which your Interface uses, you could simply do something like this:

    import netifaces as ni
    def get_interfaces():
        ifaces = ni.interfaces()
        for iface in ifaces:
            try:
                ip = ni.ifaddresses(iface)[ni.AF_INET][0]["addr"]
                print(f"IP: {ip} from Interface {iface}")
            except:
                pass
    

提交回复
热议问题