简体   繁体   English

netifaces:尝试获取Linux中所有接口的ipaddress

[英]netifaces: Trying to get ipaddress of all Interfaces in Linux

Language : Python 3.x 语言:Python 3.x

OS : Ubuntu 14.04 操作系统:Ubuntu 14.04

How to get all interfaces IP Address by using Python 3.X with netifaces module or by using any other module. 如何通过将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'}]}

I want to use 我想用

>>> len(netifaces.interfaces())
3

and want to develop some while loop which brings IPAddress for all interaces in my system. 并希望开发一些while循环,为我系统中的所有接口带来IPAddress。 But failing at the area of substituting interface name at netifaces.ifaddress() function. 但是在netifaces.ifaddress()函数中替换接口名称的区域失败。

Please let me know if you need more information. 如果您需要更多信息,请告诉我。

Thank you. 谢谢。

你可以做

list(map(lambda i:netifaces.ifaddresses(i),netifaces.interfaces()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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