in reply to Increment MAC address
I take a decimal string, convert it into a hex value,
and format it to 12 hex digits (6 octets for Mac Addy).
I segment the hex string by using the substr() function which
takes a string, start value, and distance argument. Then I
shove it into an array, and use join() to fuse it back together
into MAC Address format.
A for loop is then issued to increment the MAC address for the
iteration agrument value that is passed into the script.
The script is as follows:
#!/bin/perl #********************************************************* #***** 02/18/08 MAC Incrementor #***** Author: wilcoxc #***** Email: wilcoxc_26149@yahoo.com #***** #***** Requires 3 Arguments #***** #***Usage: macIncrementor.pl <MAC_START> <MAC_INCREMENT> <ITERATIONS> #***** #***** Purpose: This script was designed to take a decimal #***** string, convert it into a hex value, and #***** format the octets of the MAC address. #***** A for loop is then issued to increment the MAC #***** address for the iteration agrument value #***** that is passed into the script. #***** #********************************************************* my $macStart = $ARGV[0]; my $macInc = $ARGV[1]; my $macIter = $ARGV[2]; my @mac_address = qw( 00 00 00 00 00 00 ); for ($i=0; $i<$macIter; $i++) { my $hex = sprintf("%012X","$macStart"); $mac_address[0] = substr($hex, 0, 2); $mac_address[1] = substr($hex, 2, 2); $mac_address[2] = substr($hex, 4, 2); $mac_address[3] = substr($hex, 6, 2); $mac_address[4] = substr($hex, 8, 2); $mac_address[5] = substr($hex, 10, 2); my $mac_string = join(":",@mac_address); print "$mac_string\n"; $macStart+=$macInc; }
This gives you the following output:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MAC Address Incrementor
by ikegami (Patriarch) on Mar 10, 2008 at 18:30 UTC | |
by wilcoxc (Initiate) on Mar 11, 2008 at 05:14 UTC |