Skip to content

Instantly share code, notes, and snippets.

Created April 12, 2019 23:53
What would you like to do?
Utility for modifying MAC addresses on Mac ;)
set -e
get_mac_address() {
echo $(ifconfig en0 ether | grep ether | rev | cut -d' ' -f2 | rev)
get_ip_address() {
echo $(ifconfig en0 inet | grep inet | cut -d' ' -f2)
set_mac_address() {
sudo ifconfig en0 ether $1
set_branch() {
echo "Updating mac address: $(get_mac_address) -> $1"
set_mac_address $1
echo "Done. New MAC: $(get_mac_address)"
randomise_branch() {
echo "Current MAC: $(get_mac_address)"
NEW_MAC=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
set_mac_address ${NEW_MAC}
echo "Done. New MAC: $(get_mac_address)"
select_branch() {
DEVICES=$(sudo nmap -sn ${IP_ADDRESS}/24 | awk '/Nmap/{ip=$NF;next} /MAC/{printf "%s|%s|", ip,$3} /MAC/{for(i=4;i<=NF;i++) printf "%s_", $i; printf ";"} ')
# This part is needlessly clunky as, for whatever reason, the version of bash/sh on MAC misbehaves with arrays -- counts and index iteration didn't work properly
IFS=";" read -ra DEVICE_ARRAY <<< ${DEVICES}
for DEV in ${DEVICE_ARRAY[@]}; do
i=$((i+1)) && printf "\t%s) %s\n" "${i}" "${DEV}"
read -p "Select a device to spoof: " selected
NEW_MAC=$(echo ${DEVICE_ARRAY} | cut -d' ' -f${selected} | cut -d \| -f2)
echo "Spoofing MAC address: $(get_mac_address) -> ${NEW_MAC}"
set_mac_address $NEW_MAC
echo "Done. New MAC: $(get_mac_address)"
case $1 in
set_branch $2
echo "Unknown or no option given"
exit 64 # User error code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment