[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is there a utility to get IP address from interface?



Incoming from James Sinnamon:
> 
> Is there a utility to simply return the IP address of an interface, say
> eth1 or ppp0?  I need something that works like:
> 
> $ netutil eth0
> 144.133.251.117

#!/usr/bin/perl -w
use strict;
my ( $ip );
open ( IFC, "/sbin/ifconfig |" )
    or die qq($0: failed opening ifconfig pipe. $!);
while( <IFC> ) {
    if ( /P\-t\-P/ ) {
        ( undef, $ip ) = split( /:/ );
        ( $ip, undef ) = split( /  /, $ip );
        print STDOUT "$ip";
        last;
    }
}
close( IFC );


-- 
Any technology distinguishable from magic is insufficiently advanced.
(*)               http://www.spots.ab.ca/~keeling 
- -



Reply to: