如何在 Perl 中打印出可用的以太网网卡?

发布于 2024-09-24 17:54:34 字数 219 浏览 1 评论 0原文

我想知道是否可以实际打印出 Linux 机器上存在的可用以太网卡?到目前为止,我已经从“ifconfig”命令中读到了有关“Grep”的内容。

我必须使用“Net::IP”或“IO::Socket”吗?我是这种编程语言的新手,所以有人可以就如何做到这一点提供一些建议吗?

抱歉让你们困惑了!但我需要脚本在执行 perl 脚本后直接在终端打印“eth0”或“eth1”。

谢谢!

I was wondering if it's possible to actually print out the available ethernet cards that is present on a linux machine? I have so far read about "Grep" from the "ifconfig" command.

Do I have to use use "Net::IP" or "IO::Socket"? I am new to this programming language so can someone please give some advise on how to do this?

Sorry for confusing you guys! But I need the script to print like "eth0" or "eth1" directly at the terminal after excecuting the perl script.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏雨一样淡蓝的深情 2024-10-01 17:54:34

看看 Net::Address::Ethernet
它可能只是 ifconfig/ipconfig 的一个便携式包装。不过,我不会太担心这一点,因为在任何情况下你都无法避免在这里调用操作系统 - 所以调用 ifconfig 可能和任何其他选项一样好。

还有一些其他模块可能值得一看。

UPD。如果您只需要接口名称,您还可以读取文件 /proc/net/dev。现代的 Linux 应该有它,而且文件结构很容易解析。

Have a look at Net::Address::Ethernet.
It might be just a portable wrapper around ifconfig/ipconfig. Though, I wouldn't worry much about this, because in any case you can't avoid a call to OS here - so calling ifconfig is probably as good as any other option.

There are also a few other modules probably worth looking at.

UPD. If you need interface names only, you could also read a file /proc/net/dev. A modern linux should have it, and the file structure is pretty easy to parse.

南笙 2024-10-01 17:54:34

如果您仅针对 GNU/Linux 或 *BSD 进行编程,则可以使用“ifconfig”中的“grep”。

If you program for GNU/Linux or *BSD only, then you can use "grep" from "ifconfig".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文