开发者

How do I print out the available ethernet NICs in Perl?

开发者 https://www.devze.com 2023-01-17 10:30 出处:网络
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.

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 s开发者_开发百科omeone 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消