Parantelin hiukan, ip link oli turha yms.
#!/usr/bin/perl
# show IP :: raimo 120606 -> 020806
#
#INSTALL:
# wget http://dash.atspace.org/kvaak/ipa.txt
# sudo cp ipa.txt /usr/bin/ipa
# sudo chmod 755 /usr/bin/ipa
#
#RUN:
# ipa [-a -h]
use strict;
exit print "ipa [-a(all) -h(help)]\n" if grep/^-h$|^help$/, @ARGV;
exit print "$! /bin/ip\n" if !-x "/bin/ip";
my $ip = -1;
my $eth = -1;
my @all = `ip a`;
foreach(@all){
(my $trash, $eth) = split/:\s/, $_ if grep/BROADCAST.*UP/i, $_;
$ip = $_ if grep/$eth$/, $_;
last if $eth != -1 && $ip != -1;
}
$ip =~ s/inet\s|\/.*|\s{2}//g;
print "@all\n" if grep/^-a$|^all$/, @ARGV;
print "$ip" if $ip =~ /(\d+)(\.\d+){3}/ or die "error, IP not found\n";
exit 0;
#