简体   繁体   中英

Python netifaces giving unusual output

I've been using netifaces in the past with no problems but recently something changed. I am not sure whether it is windows 10 fault or pythons or maybe the netifaces itself. 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.

NOTE: Python 3.6, Netifaces 0.10.5, Windows 10

['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0'] are names of NICs in unix systems. On windows you get GUID of network interface. To get so called "friendly name" you can look up windows registry. Check out this answer (on my python 2.7 I had to import _winreg instead of winreg ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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