To increment a MAC Address, you need to convert HEX to DEC, Add AND convert DEC to HEX...
I propose this code.
sub addmac {
my ( $mac, $add ) = @_;
$mac =~ s/://g;
my $dec = hex($mac);
$mac = sprintf("%012x", $dec+$add);
return join(":", $mac =~ /(..)/g );
}
my $mac = '00:00:00:00:00:f1';
foreach ( 1 .. 32 ) {
$mac = addmac($mac,$_*4);
print "$mac\n";
}
I think others improve are possible, but it do a task.
...
00:00:00:00:01:a5
00:00:00:00:01:cd
00:00:00:00:01:f9
00:00:00:00:02:29
00:00:00:00:02:5d
...
00:00:00:00:03:9d
00:00:00:00:03:e9
00:00:00:00:04:39
00:00:00:00:04:8d
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.