I've tried to create a small and basic bash script to change my MAC address on MacOS, upon reboot. The script trows no errors, however nor does it change my mac address.
The script:
#!/bin/bash
sudo echo "Welcome"
preAddress="$(ifconfig en0|grep ether)"
numZero=2
numOne=$(( ( RANDOM % 9 ) + 0 ))
numTwo="$(openssl rand -hex 1)"
numThree="$(openssl rand -hex 1)"
numFour="$(openssl rand -hex 1)"
numFive="$(openssl rand -hex 1)"
numSix="$(openssl rand -hex 1)"
newAddress="$numZero$numOne:$numTwo:$numThree:$numFour:$numFive:$numSix"
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --disassociate
sudo ifconfig en0 ether $newAddress
networksetup -detectnewhardware
sudo ifconfig en0 up
echo "MAC Address changed to: $newAddress from$preAddress"
I've re-used some code, originally posted here: Post 1 user: seren/user137369, Post 2 User: Luke Exton, Post 3 User: OrangeTux/py4on.
In short, the script creates a set of variables which all contains a random number. These variables are formatted as a MAC Address in another variable. I then change (or at least try to) the current MAC address to the random one.
But when I run this, I see no change under Network>Advanced in system settings or if I run "ifconfig" in the terminal?
I've also tried to just copy in the following to the terminal, but no dice..:
sudo ifconfig en0 down
sudo ifconfig en0 ether 27:ab:29:b9:be:ef
sudo ifconfig en0 up
I simply cannot figure out why this does not work.. Any help is very appreciated!