More portable netifaces
In Python the PyPI module ‘netifaces’ is a popular project for retrieving information on network cards. However, on Windows it has a few problems:
It requires the .NET Framework.
It does not use proper names for interfaces (GUIDs are used on Windows.)
Additionally, pieces of information are incorrect or missing. Such as the interface number (needed on Windows), MAC address, and some subnet mask fields.
I’ve provided a wrapper around the original module to address these problems. It has the same interface as netifaces so it can be used as a drop-in replacement (it does make command-line calls and hence needs to be ran inside an event loop.)
from p2pd import *
async def example():
netifaces = await init_p2pd()
ifs = netifaces.interfaces()
# e.g. ['lo0', 'en0']
info = netifaces.ifaddresses('en0')
# {18: [{'addr': '8c:...'}], 30: [{'addr': 'fe80::...%en0',
# 'netmask': 'ffff:ffff:ffff:ffff::/64', 'flags': 1024},
# {'addr': 'fdf4:1...', 'netmask': 'ffff:ffff:ffff:ffff::/
# 64', 'flags': 1088}], 2: [{'addr': '192.168.21.144',
# 'netmask': '255.255.255.0', 'broadcast': '...'}]}
gws = netifaces.gateways()
# {'default': {2: ('192.168.21.1', 'en0')},
# 2: [('192.168.21.1', 'en0', True)],
# 30: [...]}
if __name__ == '__main__':
async_test(example)
More information on netifaces here: https://pypi.org/project/netifaces/