sub networkInfo { my @nics; my $platform = getPlatform(); if ($platform =~ /RedHat/) { my $ifconfig = qx|/sbin/ifconfig| or die("Can't get info from Linux ifconfig: $!\n"); for (split /(?<=\n)(?=\w)/, $ifconfig) { my %nic; ($nic{device}) = /^(eth\d)\s/ or next; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{ip} = $1; $nic{bcast} = $2; $nic{mask} = $3; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{ip6} = $1; } push @nics, \%nic; } } elsif ($platform =~ /SunOS/) { my $ifconfig = qx|/sbin/ifconfig -a| or die("Can't get info from Solaris ifconfig: $!\n"); for (split /(?<=\n)(?=\w)/, $ifconfig) { my %nic; ($nic{device}) = /^(fjgi\d)\s/ or next; if (/\binet addr:([\d.]+)\s.+?:([\d.]+)\s.+?:([\d.]+)/) { $nic{ip} = $1; $nic{bcast} = $2; $nic{mask} = $3; } if (/^\s+ inet6 addr:\s*(\S+)/m) { $nic{ip6} = $1; } push @nics, \%nic; } } return @nics; } for my $nic (networkInfo()) { print(join( "\t", map $_//'[undef]', @{$nic}{qw( device ip ipv6 bcast mask )} ), "\n"); }