"Beau E. Cox" wrote:
>
> Attached is a small perl script (ifinfo) I wrote to parse
> ifconfig. It gives most of the information from ifconfig,
> including MAC. It works on rh9.
I tried it out out and found a couple of problems. Your GetOptions
statement has:
'w|mac' => \$opt[2],
address => \$opt[3],
broadcast => \$opt[4],
'k|mask' => \$opt[5],
Yet the help message displayed does not show the 'mac' and 'mask'
options:
options:
-help|? brief help message
-man full documentation
-n interface Name
-t interface Type
-w hardWare address (mac)
-a Address
-b Broadcast
-k masK
-s Status
-e Everything: -n -t -w -a -b -k -s
-o one line output sep by '\'
On my eth0 interface the status was shown as 'inet6' instead of 'UP'.
Perhaps you should search for /\b(UP|DOWN)\b/i instead?
A couple of other points.
my $if = `$cmd`;
exit 255 if ($?);
$if =~ s/\n(\S)/\n:split:$1/sg;
my @aif = sort (split ':split:', $if);
Why split $if? Why not just search through it as a single string?
if $opt[2];
push (@results, /inet addr:\s*(\d+\.\d+\.\d+\.\d+)/si ? $1 : '?')
if $opt[3];
push (@results, /Bcast:\s*(\d+\.\d+\.\d+\.\d+)/si ? $1 : '?')
if $opt[4];
push (@results, /Mask:\s*(\d+\.\d+\.\d+\.\d+)/si ? $1 : '?')
The /s option affects whether or not the . (dot) metacharacter will
match a newline or not. However you are not using the dot in any of
those regular expressions.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]