News for hackers. Stuff that matters.
Re:How to randomize your MAC address on OS X by column on Wednesday June 11, 2014 @10:45AM (#7878237)
Hi again, here is a version that corrects the bug addressed by lmb:

    from random import randint
    from random import choice
    from os import getenv
    from subprocess import call
    from sys import argv

    if len(argv) > 1:
    # get network interface from cmdline parameter
        intf = argv[1]
    else:
    # get network interface from ENVIRONMENT variables
        intf = getenv('INTERFACE', '')

    if intf:
    # generate random mac address
        r = lambda: randint(0,255)
    # Universally or Locally Administered Bit and Individual/Group Bit
    # See http://packetsdropped.wordpress.com/2011/01/13/
    # mac-address-universally-or-locally-administered-bit-and-individualgroup-bit/
        sbyte = choice(['%02X' % i for i in range(255) \
                              if bin(i)[-2] == '0' and \
                                 bin(i)[-1] == '0'])
        randmac = sbyte + ':%02X:%02X:%02X:%02X:%02X' % (r(),r(),r(),r(),r())
    # change mac address
        call(["ifconfig", "%s hw ether %s" % (intf, randmac)])
    else:
        print "Couldn't determine network interface"

There are no comments on this comment yet.