[wplug] Interesting question du jour
Lance Tost
ltost at pobox.com
Mon Apr 21 16:47:49 EDT 2003
On 21 Apr 2003 billings at negate.org wrote:
> His solution is merely increasing the value of the last one, so if it's
> a character, the next character, if it's a number, it increases the
> number. It doesn't "know" about hexidecimal math.
Works on my box. And it is doing hex math.
[ltost at jupiter ltost]$ cat /tmp/infile ; /tmp/foo2; cat /tmp/foo2 ;cat
/tmp/outfile;
ppcas01 00:09:6B:49:06:F4
ppcas02 00:09:6B:63:09:F6
rcas0024 00:09:6B:49:08:2E
rcas0025 00:09:6B:49:09:12
rcas0026 00:09:6B:A3:03:ED
rcas0027 00:09:6B:63:0B:69
#!/usr/bin/perl
open (IN, "/tmp/infile") or die "Cannot open file: $!\n";
open (OUT, ">/tmp/outfile") or die "Cannot open file: $!\n";
while (<IN>) {
($host, $mac) = split;
(undef,undef,undef,undef,undef,$x) = split(':',$mac);
printf OUT ("%s\t%s\n", $host, $mac);
$y = sprintf ("%02X\n", (hex $x) + 1);
$mac =~ s/:.{2}$/:$y/;
printf OUT ("\t%s\n", $mac);
}
close (IN);
close (OUT);
ppcas01 00:09:6B:49:06:F4
00:09:6B:49:06:F5
ppcas02 00:09:6B:63:09:F6
00:09:6B:63:09:F7
rcas0024 00:09:6B:49:08:2E
00:09:6B:49:08:2F
rcas0025 00:09:6B:49:09:12
00:09:6B:49:09:13
rcas0026 00:09:6B:A3:03:ED
00:09:6B:A3:03:EE
rcas0027 00:09:6B:63:0B:69
00:09:6B:63:0B:6A
[ltost at jupiter ltost]$
>
> The solution I posted, albeit cryptic, does the hex addition, and
> handles the 0 filling. The only thing I didn't know what to do was in
> cases of FF, but that shouldn't ever occur in a MAC address, unless you
> are talking about a broadcast.
>
> On Mon, 2003-04-21 at 16:19, Vanco, Donald wrote:
> > Lance Tost wrote:
> > > This should do it... again, invalid for MACs ending in FF.
> > >
> > > #!/usr/bin/perl
> > >
> > > open (IN, "/tmp/infile") or die "Cannot open file: $!\n";
> > > open (OUT, ">/tmp/outfile") or die "Cannot open file: $!\n";
> > >
> > > while (<IN>) {
> > > ($host, $mac) = split;
> > > (undef,undef,undef,undef,undef,$x) = split(':',$mac);
> > > printf OUT ("%s\t%s\n", $host, $mac);
> > > $y = sprintf ("%02X\n", (hex $x) + 1);
> > > $mac =~ s/:.{2}$/:$y/;
> > > printf OUT ("\t%s\n", $mac);
> > > }
> > > close (IN);
> > > close (OUT);
> >
> > Getting closer - but it still does goofy things:
> > This is dorked:
> > rcas0024 00:09:6B:49:08:2E
> > 00:09:6B:49:08:3
> >
> > Yet this is OK:
> > rcas0026 00:09:6B:A3:03:ED
> > 00:09:6B:A3:03:EE
> >
> > here again:
> > rcas0029 00:09:6B:63:0B:4B
> > 00:09:6B:63:0B:5
> >
> > ...seems like the "number/letter" combo is not handled correctly
> >
> > Don
> > _______________________________________________
> > wplug mailing list
> > wplug at wplug.org
> > http://www.wplug.org/mailman/listinfo/wplug
>
--
Lance Tost <ltost at pobox.com>
More information about the wplug
mailing list