如何在Python中获取网络接口卡名称? [英] How to get Network Interface Card names in Python?

查看:99
本文介绍了如何在Python中获取网络接口卡名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python编程的新手,请耐心等待我.

I am totally new to python programming so please be patient with me.

反正有没有获取机器中NIC卡名称的信息,例如eth0,是吗?如果是这样,您该怎么做?

Is there anyway to get the names of the NIC cards in the machine etc. eth0, lo? If so how do you do it?

我已经进行了研究,但到目前为止,我只找到了仅获取IP地址和MAC地址的代码,例如

I have researched but so far I have only found codes to get IP addresses and MAC addresses only such as

import socket
socket.gethostbyname(socket.gethostname())

有关代码的建议将不胜感激.谢谢!

Advice on the codes would really be appreciated. Thanks!

推荐答案

我认为标准库中没有什么可以查询这些名称的.

I don't think there's anything in the standard library to query these names.

如果在Linux系统上需要这些名称,我将解析ifconfig的输出或/proc/net/dev的内容.请查看此博客条目,以解决类似问题.

If I needed these names on a Linux system I would parse the output of ifconfig or the contents of /proc/net/dev. Look at this blog entry for a similar problem.

这篇关于如何在Python中获取网络接口卡名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆