Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: How to increment a MAC Address?

by dorward (Curate)
on May 23, 2005 at 09:19 UTC ( #459476=note: print w/replies, xml ) Need Help??

in reply to How to increment a MAC Address?

Something like this perhaps?

$" = ':'; for (my $int = 1; $int <= 999999999999; $int++) { my $leading = sprintf("%012d", $int); my @split = ($leading =~ /../g); print "@split\n"; }

Replies are listed 'Best First'.
Re^2: How to increment a MAC Address?
by rob_au (Abbot) on May 23, 2005 at 09:33 UTC
    The components of a MAC address, when expressed as a group of six octet values, are expressed as hexadecimal values (eg. FE:DC:BA:01:23:45) - Your code does not account for this with the maximal octet value of 99 (decimal) provided by your code.

    Although in stating this, I should note that this is a problem too with the problem description in the original thread post.


    perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"

      yes, i know 99 is not valid, just that im simulating something out here, where i require the value as 99 and not in hex.
        if $_ holds your string, then this should increment it
        $_ = join ":",unpack "A2"x6, substr( ('0' x 12 . (1 + join '',split /:/,$_))), -12)
Re^2: How to increment a MAC Address?
by aditya.singh (Acolyte) on Jun 16, 2005 at 12:24 UTC
    You code prints:

    OP wants:
    00:00:00:00:02:99 and so on.

    Note: Once the pair of digit reaches 99, it does not roll back to 00.

      I've just tested it and it increments as expected (i.e. it does get past 1).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://459476]
[shmem]: perldigious: as always - if it ain't broke, don't fix it. Ther must be a very compelling reason for changing column names in a database. Those are rare.
[Corion]: If you have whitespace in the column names in the database, whap the DBAs ;)
[shmem]: It's common for some vendors to have column names such as WRSTVG or some other such whizzbang, and another table where these names are mapped to something meaningful depending on how you look at the data
[shmem]: afair in SAP that occurs all the time

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2017-05-25 13:38 GMT
Find Nodes?
    Voting Booth?