Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: How to increment a MAC Address?

by Rhose (Priest)
on Jun 16, 2005 at 14:28 UTC ( #467287=note: print w/replies, xml ) Need Help??

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"
    Mac address= 00:19:D1:F6:F7:F1 Mac address= 00:19:D1:F6:F7:00

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://467287]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-03-24 15:43 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.