0

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!

Cyrus
  • 84,225
  • 14
  • 89
  • 153
LeeSwaggers
  • 33
  • 1
  • 3
  • This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Feb 16 '19 at 21:46
  • I can't reproduce this. What version of macOS is this? What does `ifconfig en0` say after you run this by hand? – Rob Napier Feb 16 '19 at 22:33
  • @RobNapier - So it works for you? if I use "ifconfig en0" it simply has the permanent MAC Address (original).. – LeeSwaggers Feb 16 '19 at 22:39
  • Yeah; works without trouble. macOS 10.14.3, just running the 3 lines by hand, and then checking w/ `ifconfig eth0`. – Rob Napier Feb 16 '19 at 22:42
  • I'm on 10.14.1, which should be a deal breaker as far as I know. You say the three separate lines work, but does it work if you use the entire script then? – LeeSwaggers Feb 16 '19 at 22:47

0 Answers0