Skip to content

Instantly share code, notes, and snippets.

@ochronus
Created June 10, 2014 15:41
Show Gist options
  • Save ochronus/33ddbc15f875158ce0aa to your computer and use it in GitHub Desktop.
Save ochronus/33ddbc15f875158ce0aa to your computer and use it in GitHub Desktop.
#/bin/sh
MD5_TOOL=md5 # on linux set this to 'md5sum'
IFACE=en0 # probably eth0, etc on linux
RANDOM_MAC_ADDRESS=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null|${MD5_TOOL}|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5:\6/')
sudo ifconfig ${IFACE} ether ${RANDOM_MAC_ADDRESS}
if [[ $? != 0 ]] ; then
echo "Error changing the MAC address of ${IFACE}"
exit 1
else
echo "The interface ${IFACE} has the MAC address: ${RANDOM_MAC_ADDRESS}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment