Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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.


Comment on Re: How to increment a MAC Address?
Download Code
Replies are listed 'Oldest 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
Reaped: Re^2: How to increment a MAC Address?
by NodeReaper (Curate) on Dec 13, 2011 at 13:52 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2015-07-07 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (92 votes), past polls