----- Original Message ----- 
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 19, 2003 8:42 AM
Subject: Re: How to retrieve a MAC address


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

Gee John - I didn't post it just to get shot down ;)

Ok - good points.

Aloha => Beau;

PS: I know what the /s option does; as you know there
are many ways to skin the Perl cat - and my style may
be different than yours. I code to get the job out, not
to always look 'pretty' - this script was whipped up
for a client in about 1 hr, and it's working for him. That
it may be idiosyncratic and not work everywhere ignores
the fact that it was origionally a quick-and-dirty and then I
moved on to other things. Wheels that don't squeak don't
get too much of my attention - and I think I am almost
done with this rant but I have been crashing on a project
for the last 30+ hours and need some beddie-bye time
and a long walk OUTSIDE and I know I will not be so
crabbie when I wake up and now good night, and,
thanks, really, for your time in reviewing my script
and that's all folks....


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to