finding ethernet interfaces and IPs

Discussion in 'Perl Misc' started by Zebee Johnstone, Nov 9, 2004.

  1. 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


    --
    Zebee Johnstone (), proud holder of
    aus.motorcycles Poser Permit #1.
    "Motorcycles are like peanuts... who can stop at just one?"
    Zebee Johnstone, Nov 9, 2004
    #1
    1. Advertising

  2. In comp.lang.perl.misc on Tue, 09 Nov 2004 03:51:17 GMT
    Zebee Johnstone <> wrote:
    >
    > 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
    Zebee Johnstone, Nov 9, 2004
    #2
    1. Advertising

  3. Zebee Johnstone <> wrote in
    news::

    > 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?

    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
    A. Sinan Unur, Nov 9, 2004
    #3
  4. Zebee Johnstone wrote:
    > 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
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Nov 9, 2004
    #4
  5. Zebee Johnstone

    Ben Morrow Guest

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


    Try Net::pCap.

    Ben

    --
    I must not fear. Fear is the mind-killer. I will face my fear and
    I will let it pass through me. When the fear is gone there will be
    nothing. Only I will remain.
    Frank Herbert, 'Dune'
    Ben Morrow, Nov 9, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe
    Replies:
    0
    Views:
    1,662
  2. Replies:
    0
    Views:
    1,166
  3. xanoutas

    get IPs at a LAN

    xanoutas, Dec 13, 2005, in forum: Java
    Replies:
    4
    Views:
    2,613
    Chris Uppal
    Dec 13, 2005
  4. Iñaki Baz Castillo
    Replies:
    3
    Views:
    108
    Iñaki Baz Castillo
    May 11, 2011
  5. Adam Funk
    Replies:
    12
    Views:
    643
    Adam Funk
    Jul 5, 2005
Loading...

Share This Page