【问题标题】:How to count the number of network interfaces available in a system using python script?如何使用 python 脚本计算系统中可用网络接口的数量?
【发布时间】:2019-04-24 04:57:02
【问题描述】:

我有一个 python 脚本,它使用 shell 命令来检索可用接口的数量。我想知道如何使用python库来统计接口的数量。

这是我目前用来计算可用接口数量的代码部分: numberOfInterfaces = int(os.popen('ls -A /sys/class/net | wc -l').read())

【问题讨论】:

标签: python python-3.x python-2.7


【解决方案1】:

https://pypi.org/project/netifaces

$ pip install netifaces

// network_interfaces.py
import netifaces
print("Total Interfaces : {}".format(len(netifaces.interfaces())))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多