Skip to content

Instantly share code, notes, and snippets.

@trotzig
Created May 15, 2017 09:02
Show Gist options
  • Save trotzig/7783e7fc6b5f03b7386d94edc91647c6 to your computer and use it in GitHub Desktop.
Save trotzig/7783e7fc6b5f03b7386d94edc91647c6 to your computer and use it in GitHub Desktop.
if [ ! -f .ORIGINAL_MAC_ADDRESS ]; then
ifconfig en0 | grep ether | cut -d' ' -f2 > .ORIGINAL_MAC_ADDRESS
echo "Backup of original MAC address saved in .ORIGINAL_MAC_ADDRESS"
fi
if [[ -z "$1" ]]; then
echo "Usage: ./new-mac-address.sh [generate|reset]"
exit 0
fi
if [[ "$1" = "generate" ]]; then
MAC=da:`openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//'`
elif [[ "$1" = "reset" ]]; then
MAC=`cat .ORIGINAL_MAC_ADDRESS`
else
echo "Unknown command: $1"
exit 0
fi
echo "Changing the MAC to $MAC. You may be asked for a root password."
sudo ifconfig en0 ether $MAC
@trotzig
Copy link
Author

trotzig commented May 15, 2017

How to use this script:

To generate a new mac address, run

 ./new-mac-address.sh generate

This will save a .ORIGINAL_MAC_ADDRESS file in the current directory. Then, to restore your old mac address, run

./new-mac-address.sh reset

Restoring the original mac address isn't strictly needed, but can be helpful if you have external devices (e.g. other wifi routers) that have your mac address stored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment