Re:How to randomize your MAC address on OS X
by column on Tuesday June 10, 2014 @12:04PM
(#7873343)
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.)
[ Parent
| on HN ]
This code will lead to a nice, self-inflicted bug that will sometimes break your network connection. The low two bits of the first byte of the MAC have a special purpose and should be kept at 0 [1]. Learned this the hard way when developing on an embedded TCP stack. The switch silently discarded packets from multicast or local MAC addresses.
[1] http://en.wikipedia.org/wiki/MAC_address#Address_details
You can use tricks based on multicast ethernet to detect interfaces in promiscuous mode:
That's pretty cool, thanks for the hint. The original PDF seems to be from 2001, does this still work?
Re:How to randomize your MAC address on OS X
by column on Wednesday June 11, 2014 @05:04AM
(#7877043)
Thank you for pointing this out.
Re:How to randomize your MAC address on OS X
by column on Wednesday June 11, 2014 @10:31AM
(#7878174)
I found this link to be more easily understandable than Wikipedia :
http://packetsdropped.wordpress.com/2011/01/13/mac-address-u...
Re:How to randomize your MAC address on OS X
by grinich on Tuesday June 10, 2014 @12:32PM
(#7873550)
I feel like it should be outlawed to post untested code that must run as root. :/
Re:How to randomize your MAC address on OS X
by column on Wednesday June 11, 2014 @05:15AM
(#7877072)
It's not like this is obfuscated code. I clearly mentioned this is untested, and it turns out it contains a major bug. But it starts a conversation, and made me learn about that significant bit in the mac address, should I pay a fine for starting a conversation?
Please do not advocate for prior restraint, even jokingly.
Re:How to randomize your MAC address on OS X
by pjlegato on Tuesday June 10, 2014 @04:33PM
(#7875142)
Er. But you're advocating prior restraint of advocacy of prior restraint.
Re:How to randomize your MAC address on OS X
by aliakbarkhan on Tuesday June 10, 2014 @09:20PM
(#7876167)
Asking someone not to talk about something isn't the same thing as advocating that talking about something should be "outlawed".
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"
Re:How to randomize your MAC address on OS X
by easytiger on Wednesday June 11, 2014 @04:35AM
(#7876972)
that really should be a bash script, not a python one.
Re:How to randomize your MAC address on OS X
by column on Wednesday June 11, 2014 @05:04AM
(#7877042)
why?
Re:How to randomize your MAC address on OS X
by easytiger on Wednesday June 11, 2014 @06:05AM
(#7877169)
Because mostly you are just shelling out. Also you can't just use any mac addr as some bits are reserved, e.g. multicast.
But you can collapse that as so or suchlike:
ifconfig eth34 hw ether $(openssl rand 6 | xxd -p | sed 's/\(..\)/\1:/g; s/:$//')
Obviously doing this is wrong anyway but that will do what your script does.