Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gilvegliach
Last active February 10, 2020 14:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilvegliach/24bc2bfdf45bf1bfa61303722cb48b97 to your computer and use it in GitHub Desktop.
Save gilvegliach/24bc2bfdf45bf1bfa61303722cb48b97 to your computer and use it in GitHub Desktop.
Increase and decrease your MAC address
#!/usr/bin/env bash
#
# Usage:
# mac-incr # increase the MAC address
# mac-incr -d # decrease the MAC address
#
set -e
INTERFACE="en0"
function mac_add_delta() {
local mac="0x${1//\:/}"
local delta="$2"
local new_mac="$(printf "%x" $((mac + delta)))" # no 0x
echo "${new_mac:0:2}:${new_mac:2:2}:${new_mac:4:2}:${new_mac:6:2}:${new_mac:8:2}:${new_mac:10:2}"
}
if [[ $1 == "-d" ]]; then
DELTA="-1"
else
DELTA="+1"
fi
MAC=$(ifconfig "$INTERFACE" | grep ether | tr -d ' \t' | cut -c 6-42)
NEW_MAC=$(mac_add_delta "$MAC" "$DELTA")
echo "$INTERFACE old mac: $MAC"
echo "$INTERFACE new mac: $NEW_MAC"
echo "Applying setting with sudo"
sudo ifconfig "$INTERFACE" ether "$NEW_MAC"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment