【发布时间】:2016-05-15 01:04:25
【问题描述】:
语言:Python 3.x
操作系统:Ubuntu 14.04
如何通过使用带有 netifaces 模块的 Python 3.X 或使用任何其他模块来获取所有接口的 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() 函数中替换接口名称方面失败。
如果您需要更多信息,请告诉我。
谢谢。
【问题讨论】:
标签: python linux ubuntu ip-address