简体   繁体   English

Python netifaces提供异常输出

[英]Python netifaces giving unusual output

I've been using netifaces in the past with no problems but recently something changed. 我过去一直在使用netifaces,没有问题,但最近有所变化。 I am not sure whether it is windows 10 fault or pythons or maybe the netifaces itself. 我不确定是Windows 10错误还是python或netifaces本身。 Anyways here is what happens. 无论如何,这是发生了什么。

According to docs the code: 根据文档的代码:

import netifaces

netifaces.interfaces()

Should give me the result similar to this: 应该给我类似的结果:

['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']

While in my case what I get is: 在我看来,我得到的是:

['{E3EE4C5B-38D5-4E38-ABD3-912690B3333B}', '{07ED21E7-D11D-4FAE-BCAB-00748015A895}', '{9F401909-A4A5-4AB6-8617-DFA205446FC6}', '{073251CD-250D-4FAA-889A-560941A96782}', '{6613CF18-67E7-4499-8716-58EEC449E5C6}', '{C1568B39-575B-46B3-8EA7-95A7DBA33DD0}', '{F7F856C1-2EEE-4291-B42C-444C28D7C389}', '{2FD83117-396D-11E7-81F5-806E6F6E6963}']

At this point I don;t know what I am dealing with and what to choose next. 在这一点上,我不知道我要处理什么以及下一步要选择什么。 But using at random any of the results like this: 但是随机使用以下任何结果:

netifaces.ifaddresses('{07ED21E7-D11D-4FAE-BCAB-00748015A895}')

Also returns some kind of 'encrypted' results: 还返回某种“加密”结果:

{-1000: [{'addr': 'fc:f8:ae:15:6f:0e'}], 23: [{'addr': 'fe80::ec58:f02f:37d0:598b%4', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128', 'broadcast': 'fe80::ec58:f02f:37d0:598b%4'}]}

Instead of the way it is presented in docs (looks more user friendly, doesn't it?): 而不是在文档中呈现的方式(看起来更加用户友好,不是吗?):

{18: [{'addr': ''}], 2: [{'peer': '127.0.0.1', 'netmask': '255.0.0.0', 'addr': '127.0.0.1'}], 30: [{'peer': '::1', 'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', 'addr': '::1'}, {'peer': '', 'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::1%lo0'}]}

Can someone explain me please what is happening and how to 'decipher' these results? 有人可以向我解释一下正在发生什么以及如何“解读”这些结果吗? What I am trying to do in the end is to obtain ip addresses of all network interfaces my pc is using. 最后,我想做的是获取我的PC正在使用的所有网络接口的IP地址。

NOTE: Python 3.6, Netifaces 0.10.5, Windows 10 注意:Python 3.6,Netifaces 0.10.5,Windows 10

['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0'] are names of NICs in unix systems. ['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']是UNIX系统中NIC的名称。 On windows you get GUID of network interface. 在Windows上,您将获得网络接口的GUID To get so called "friendly name" you can look up windows registry. 要获得所谓的“友好名称”,您可以查找Windows注册表。 Check out this answer (on my python 2.7 I had to import _winreg instead of winreg ). 看看这个答案 (在我的python 2.7上,我必须导入_winreg而不是winreg )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM