Comment

Comment by column

Hi, isn't Python now shipping with OSX? I haven't tested it, but wouldn't this also work while being more readable? (DISCLAIMER: I haven't tested it. Also, I haven't tested it.)

    from random import randint
    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)
        randmac = '%02X:%02X:%02X:%02X:%02X:%02X' % (r(),r(),r(),r(),r(),r())
    # change mac address
        call(["ifconfig", "%s hw ether %s" % (intf, randmac)])
    else:
        print "Couldn't determine network interface"
parent column 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton