Skip to content

Instantly share code, notes, and snippets.

@Lifelovinglight
Last active January 25, 2017 13:33
Show Gist options
  • Save Lifelovinglight/cfdebf2ac49a9a9d3150d4bb8a3a38cd to your computer and use it in GitHub Desktop.
Save Lifelovinglight/cfdebf2ac49a9a9d3150d4bb8a3a38cd to your computer and use it in GitHub Desktop.
Tiniest mac changer, keeps your manufacturer hardware prefix.
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <interface label>"
else
NEW_MAC=$(ip link show $1 | tail -n1 | grep -Po 'link/ether \K[[:xdigit:]:]{8,8}')
for i in {0..2}; do
printf -v BYTE "%02x" $(($RANDOM%256))
NEW_MAC=$NEW_MAC:$BYTE
done
ip link set dev $1 address $NEW_MAC
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment