Please visit the new Mac-Forums Facebook page:
Join Us @ Mac-Forums Facebook Page



Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Change MAC address
    imfromwales's Avatar
    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 address
    I am trying to change my MAC address but im having problems. I have tried checking my MAC address with
    Code:
    ifconfig en1 | grep ether
    and that results in my correct MAC address.

    I then try to change it by
    Code:
    sudo ifconfig en1 ether af:f8:35:2a:26:c6
    , with me wanting the MAC address to be
    Code:
    af:f8:35:2a:26:c6
    , although when I check my mac address it stil stays as the original.

    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

  2. #2
    Change MAC address
    imfromwales's Avatar
    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

  3. #3
    Change MAC address
    vansmith's Avatar
    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

  4. #4
    Change MAC address
    imfromwales's Avatar
    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

  5. #5
    Change MAC address
    McYukon's Avatar
    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/.$//'
    With this,
    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
    You can make it openable like a regular application by changing it's file extension from .sh to .command
    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.

  6. #6
    Change MAC address
    imfromwales's Avatar
    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!

  7. #7
    Change MAC address
    vansmith's Avatar
    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

  8. #8
    Change MAC address
    imfromwales's Avatar
    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?

  9. #9
    Change MAC address
    vansmith's Avatar
    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
    Change that to en1 and you should be good to go.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  10. #10
    Change MAC address
    imfromwales's Avatar
    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
    I have removed the last 6 parts of my MAC address. This is the same as my old MAC address for some reason

  11. #11
    Change MAC address
    vansmith's Avatar
    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

  12. #12
    Change MAC address
    imfromwales's Avatar
    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
    Can somebody please suggest why, when I change the script to encorporate the random generator, it does not change the MAC address?

  13. #13
    Change MAC address
    vansmith's Avatar
    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

  14. #14
    Change MAC address
    imfromwales's Avatar
    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?

  15. #15
    Change MAC address
    McYukon's Avatar
    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 Editor
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HowTo Change Text Address of My Mac
    By kimberlysmoore in forum macOS - Operating System
    Replies: 0
    Last Post: 03-18-2010, 03:13 PM
  2. using terminal to change mac address
    By appleXcore in forum macOS - Operating System
    Replies: 0
    Last Post: 09-03-2008, 11:54 PM
  3. How do i change my MAC address
    By chilbury in forum Internet, Networking, and Wireless
    Replies: 11
    Last Post: 03-02-2008, 08:02 AM
  4. Can I change my email address on .mac?
    By markw10 in forum macOS - Operating System
    Replies: 1
    Last Post: 08-14-2007, 12:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •