http://qs321.pair.com?node_id=467287


in reply to How to increment a MAC Address?

I missed this thread earlier, and the approach I took is pretty similar to zengargoyle's.

#!/usr/bin/perl use strict; use warnings; #use constant MAX_VAL => 255; use constant MAX_VAL => 99; my @MAC=(0) x 6; sub PrintMAC { # print join(':',map {sprintf('%02X',$_)} @_),"\n"; print join(':',map {sprintf('%02D',$_)} @_),"\n"; } my $CurNO = 5; while ($CurNO >= 0) { while ($MAC[$CurNO] < MAX_VAL) { PrintMAC(@MAC); $MAC[$CurNO]++; } $CurNO--; } PrintMAC(@MAC);

On a side note... if you uncomment the two commented lines and comment out the lines immediately below them, you'll get addresses in the full range.

Replies are listed 'Best First'.
Re^2: How to increment a MAC Address?
by Anonymous Monk on Dec 13, 2011 at 13:51 UTC
    Here i using the code for increment MAC address of last bit after increment last bit overflow so to over come again recount from starting eg: last position is FF then after we increment by 1 we start count by 00 ----------------
    #!/bin/sh mac=$(ifconfig eth0|grep HWaddr|awk '{print $5}'| tr '[a-z]' '[A-Z]' | + cut -d ':' -f1-5) maclast=$(ifconfig eth0|grep HWaddr|awk '{print $5}'| tr '[a-z]' '[A-Z +]' | cut -d ':' -f6) echo "Mac address= $mac:$maclast" decmac=$(echo "ibase=16; $maclast"|bc) if [ $decmac -eq '241' ] then macinc='00' else incout=`expr $decmac + 1 ` macinc=$(echo "obase=16; $incout"|bc) fi echo "Mac address= $mac:$macinc"
    OUTPUT:
    Mac address= 00:19:D1:F6:F7:F1 Mac address= 00:19:D1:F6:F7:00