tags:

views:

79

answers:

2

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!

A: 

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

Drakmail
Is there any way to use any PERL only related commands? Instead of using unix commands?
JavaNoob
I think it http://search.cpan.org/~lds/IO-Interface-0.98/Interface.pm is that are you need.
Drakmail
Thank you for your reply. I have read through the IO interface but I can't seem to get the command to retrieve only the interface number. Any thoughts on that?
JavaNoob
@JavaNoob, what exactly do you mean by the "interface number"? The 0 in `eth0`? What about interfaces that aren't named `eth`, like WiFi cards?
cjm
Ok what I need the perl script to do is to print out "eth 0" or other NIC cards like "lo" or "eth1"....
JavaNoob
+2  A: 

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.

VladV
Nope.....It only prints the MAC address and not the interface number.
JavaNoob