finding ethernet interfaces and IPs

  • Thread starter Zebee Johnstone
  • Start date
Z

Zebee Johnstone

I have a machine with more than one ethernet interface, and several
IP's aliased to the interfaces.


And several machines with aliases but only one interface.

So I don't want to hardcode interface names like eth0 into anything.

I want a list of IP addresses on the machine and the interface each IP
lives on.

I've been using grep and awk on the output from ifconfig -a to get the
IPs for use in a shellscript, but the new interface has kyboshed that as
ifconfig puts the interface name and IP address on different lines.

So I thought I should write a short perlscript to produce the
information for the shellscript.

Is there a module I can use to get the information, or will I have to
OPEN an ifconfig pipe and parse what I get from that? I'm trying to
avoid shell calls in perl if I can.

I've searched on CPAN but couldn't find anything that understood both
interface and IP.

Zebee
 
Z

Zebee Johnstone

In comp.lang.perl.misc on Tue, 09 Nov 2004 03:51:17 GMT
Zebee Johnstone said:
I've searched on CPAN but couldn't find anything that understood both
interface and IP.

as a followup, I did (afer I posted this of course) find Net::Interface
and Net::Ifconfig:Wrapper, but neither would compile on my system.

This may indicate I'm missing a library, but I've no idea how to find
which one. As far as I know it's pretty complete.

Zebee
 
A

A. Sinan Unur

I have a machine with more than one ethernet interface, and several
IP's aliased to the interfaces.
....

Is there a module I can use to get the information, or will I have to
OPEN an ifconfig pipe and parse what I get from that? I'm trying to
avoid shell calls in perl if I can.

I've searched on CPAN but couldn't find anything that understood both
interface and IP.

http://search.cpan.org/search?query=network+interface&mode=all

returns

http://search.cpan.org/~lds/IO-Interface-0.98/Interface.pm

Does that help?
 
J

John W. Krahn

Zebee said:
I have a machine with more than one ethernet interface, and several
IP's aliased to the interfaces.

And several machines with aliases but only one interface.

So I don't want to hardcode interface names like eth0 into anything.

I want a list of IP addresses on the machine and the interface each IP
lives on.

I've been using grep and awk on the output from ifconfig -a to get the
IPs for use in a shellscript, but the new interface has kyboshed that as
ifconfig puts the interface name and IP address on different lines.

If your ifconfig output is the same as mine then this should be close to what
you need:

ifconfig -a | perl -l -00ne'print/^(\w+\s).+?inet addr:([\d.]+)/s'


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top