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

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

问题描述

我对 Python 编程完全陌生,所以请耐心等待.

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

有没有办法获取机器中网卡的名称等.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天全站免登陆