netifaces:尝试获取 Linux 中所有接口的 IP 地址
netifaces: Trying to get ipaddress of all Interfaces in Linux
Language : Python 3.x
OS : Ubuntu 14.04
如何使用 Python 3.X 和 netifaces 模块或使用任何其他模块来获取所有接口的 IP 地址。
>>> netifaces.interfaces()
['lo', 'eth0', 'eth1']
>>> netifaces.interfaces()
['lo', 'eth0', 'eth1']
>>> netifaces.ifaddresses('eth0')
{17: [{'broadcast': 'ff:ff:ff:ff:ff:ff', 'addr': '08:00:27:5b:24:09'}], 2: [{'broadcast': '10.0.2.255', 'netmask': '255.255.255.0', 'addr': '10.0.2.15'}], 10: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::a00:27ff:fe5b:2409%eth0'}]}
我想用
>>> len(netifaces.interfaces())
3
并想开发一些 while 循环,为我系统中的所有接口带来 IPAddress。但是在 netifaces.ifaddress()
函数中替换接口名称的区域失败。
如果您需要更多信息,请告诉我。
谢谢。
你可以做到
list(map(lambda i:netifaces.ifaddresses(i),netifaces.interfaces()))
Language : Python 3.x
OS : Ubuntu 14.04
如何使用 Python 3.X 和 netifaces 模块或使用任何其他模块来获取所有接口的 IP 地址。
>>> netifaces.interfaces()
['lo', 'eth0', 'eth1']
>>> netifaces.interfaces()
['lo', 'eth0', 'eth1']
>>> netifaces.ifaddresses('eth0')
{17: [{'broadcast': 'ff:ff:ff:ff:ff:ff', 'addr': '08:00:27:5b:24:09'}], 2: [{'broadcast': '10.0.2.255', 'netmask': '255.255.255.0', 'addr': '10.0.2.15'}], 10: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::a00:27ff:fe5b:2409%eth0'}]}
我想用
>>> len(netifaces.interfaces())
3
并想开发一些 while 循环,为我系统中的所有接口带来 IPAddress。但是在 netifaces.ifaddress()
函数中替换接口名称的区域失败。
如果您需要更多信息,请告诉我。
谢谢。
你可以做到
list(map(lambda i:netifaces.ifaddresses(i),netifaces.interfaces()))