Results 1 to 15 of 22
Thread: Change MAC address
-
11-11-2013, 09:52 PM #1
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Change MAC addressI am trying to change my MAC address but im having problems. I have tried checking my MAC address with
Code:ifconfig en1 | grep ether
I then try to change it byCode:sudo ifconfig en1 ether af:f8:35:2a:26:c6
Code:af:f8:35:2a:26:c6
How can I change it?
I know it resets every time I reset my computer, so I was planning on ultimately writing a script that, if the WIFI is on, turn it off, then change my MAC address to a random address and then turn WIFI back on.
Any help is greatly appreciated
- 11-11-2013, 10:02 PM #2
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Ok, I have corrected the error, I can now change the MAC address.
I have also the correct commands to turn the wifi on/off and also creating a random MAC number, but I dont know how I can actually create a file that executes the commands. The code I have is below
Code:#Turn wifi off networksetup -setairportpower en1 off #Generate random MAC address randomAddress = openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' #set MAC address to random address sudo ifconfig en0 ether randomAddress #Turn wifi on networksetup -setairportpower en1 on
11-11-2013, 10:13 PM #3
- Member Since
- Oct 19, 2008
- Location
- Toronto
- Posts
- 19,853
- Your Mac's Specs
- Early 2015 13" rMBP
- Rep Power
- 31
Looking at the man page, it looks like you want the "lladdr" option instead of the "ether" one. I might be wrong but it's worth a shot.
Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
11-11-2013, 10:18 PM #4
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
I have managed to get the script working by saving it as a .sh file but I cant get the random Mac address generated correctly, I have to enter the MAC address in the script. This is fine but I would like a random one each time I run the script. Below is my script so far:
Code:#Turn wifi off networksetup -setairportpower en1 off #Generate random MAC address set randomAddress = openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' #set MAC address to random address sudo ifconfig en0 ether $randomAddress #Turn wifi on networksetup -setairportpower en1 on
11-11-2013, 11:07 PM #5
- Member Since
- May 14, 2009
- Location
- Near Whitehorse, Yukon
- Posts
- 2,052
- Your Mac's Specs
- 2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
- Rep Power
- 13
Try replacing this,
Code:set randomAddress = openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
Code:randomAddress=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
Oh and after you make your script executable with
Code:chmod +x pathToScript.sh
Use the reputation system if a post helps you!
Mac Forums IRC Channel - Help build it by hanging out with us
The next sentence is true. The previous sentence is false.
11-11-2013, 11:13 PM #6
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Perfect, thanks!
11-12-2013, 11:14 AM #7
- Member Since
- Oct 19, 2008
- Location
- Toronto
- Posts
- 19,853
- Your Mac's Specs
- Early 2015 13" rMBP
- Rep Power
- 31
Please don't delete your posts in the future. If someone has the same issue (or a similar one) in the future, it's nice to have the conversation and solution up for others.
Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
11-12-2013, 07:39 PM #8
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Ok. Point taken in.
I have realised it does not change the MAC address for the wifi, it only changes it if it is 'en0' which is the ethernet no?
I still have the same MAC address after running the script for some reason?
11-12-2013, 07:41 PM #9
- Member Since
- Oct 19, 2008
- Location
- Toronto
- Posts
- 19,853
- Your Mac's Specs
- Early 2015 13" rMBP
- Rep Power
- 31
Because you've only changed it for en0.
Look at line two of your script:Code:sudo ifconfig en0 ether $randomAddress
Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
11-12-2013, 07:59 PM #10
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Even after changing that to en1, I got an error. The script ran but does not change the en1 MAC address
Code:my-macbook:RND Me$ ./test.sh en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500 ether 00:e3:e4:xx:xx:xx
11-12-2013, 08:59 PM #11
- Member Since
- Oct 19, 2008
- Location
- Toronto
- Posts
- 19,853
- Your Mac's Specs
- Early 2015 13" rMBP
- Rep Power
- 31
If you do the four commands individually, do they work then?
I also just noticed that the script requires elevated privileges at points. Are you passing the script your user password at any point?Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
11-13-2013, 03:16 AM #12
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Yes the 4 of them work individually. I have had to modify the script, to get it kind of working, although the random number implementation is not working.
I have had to hard code the new MAC address in, which is not great as I want it to change randomly whenever the script is ran. Below is the code I have which changes the wifi MAC code to a pre defined one.
Code:#Turn wifi off sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z sleep 10 #Generate random MAC address randomAddress=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//') #set MAC address to random address sudo ifconfig en1 ether cc:cc:dd:dd:ee:ff #Turn wifi on networksetup -setairportpower en1 on
11-13-2013, 09:56 AM #13
- Member Since
- Oct 19, 2008
- Location
- Toronto
- Posts
- 19,853
- Your Mac's Specs
- Early 2015 13" rMBP
- Rep Power
- 31
As I asked earlier, how are you passing your password to satisfy that requirement for sudo? If you don't execute it with the elevated privileges (executing the script with sudo) or pass it your password, it's going to fail.
Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
11-13-2013, 10:35 PM #14
- Member Since
- Apr 11, 2013
- Posts
- 194
- Your Mac's Specs
- 13" rMBP 2014, 8GB RAM, 128GB SSD, 2.6GHz i5
- Rep Power
- 7
Oh, sorry. I am not passing it my password, I thought because I am the admin, and log in as admin I would not need the password. How can I pass the password to the script?
Does the script work for you when you run it, if you pass it your password?
11-13-2013, 11:18 PM #15
- Member Since
- May 14, 2009
- Location
- Near Whitehorse, Yukon
- Posts
- 2,052
- Your Mac's Specs
- 2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
- Rep Power
- 13
The only secure way to do this is like this, replace the filepaths/username with your own path/username. You can find the path by dropping the script into a terminal window or running it.
Step 1
sudo chown root:root /path/filename.sh
sudo chmod 700 /path/filename.sh
Step 2
Set up sudo to allow filename.sh to execute without requiring a password
Type sudo visudo at the terminal to open the sudo permissions (sudoers) file
Around line 25, you'll see this line: %sudo ALL=(ALL:ALL) ALL
Below that line, insert the following line, where username is your username:
username ALL=(ALL) NOPASSWD: /path/filename.sh
Depeding what your system is set to either vim or nano will open the file for you to edit.
For saving the file via the nano editor: Exit the editor (Ctrl+X)
For saving the file via the vim editor: Press [Esc] key and then : (the colon) then type wq and hit enter
Collected from:
bash - How do I sudo a command in a script without being asked for a password? - Ask Ubuntu
HowTo: Save File in Vi / Vim Text EditorUse the reputation system if a post helps you!
Mac Forums IRC Channel - Help build it by hanging out with us
The next sentence is true. The previous sentence is false.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
HowTo Change Text Address of My Mac
By kimberlysmoore in forum macOS - Operating SystemReplies: 0Last Post: 03-18-2010, 03:13 PM -
using terminal to change mac address
By appleXcore in forum macOS - Operating SystemReplies: 0Last Post: 09-03-2008, 11:54 PM -
How do i change my MAC address
By chilbury in forum Internet, Networking, and WirelessReplies: 11Last Post: 03-02-2008, 08:02 AM -
Can I change my email address on .mac?
By markw10 in forum macOS - Operating SystemReplies: 1Last Post: 08-14-2007, 12:50 AM