Script to find all network adapters I'm connected to in Python

只谈情不闲聊 提交于 2019-12-07 08:22:25

netifaces would be a good start. From the docs:

It's been annoying me for some time that there's no easy way to get the address(es) of the machine's network interfaces from Python. [...]

This package attempts to solve that problem.

Some relevant examples:

>>> netifaces.interfaces()
['lo0', 'gif0', 'stf0', 'en0', 'en1', 'fw0']

>>> netifaces.ifaddresses('lo0')
{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'}]}

Get it with pip install netifaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!