New random mac address for lan and wifi upon each restart?

Discussion in 'macOS' started by MacRaccoon, Feb 21, 2013.

  1. MacRaccoon macrumors member

    Joined:
    Feb 12, 2013
    #1
    I'm looking for a way to generate new random mac address for both lan and wifi upon boot.
    Has anyone stumbled upon such scripts?
     
  2. ChristianJapan macrumors 601

    ChristianJapan

    Joined:
    May 10, 2010
    Location:
    日本
    #2
    Why you want that? What are you trying ? Sounds like you have to hide something :confused:
     
  3. MacRaccoon thread starter macrumors member

    Joined:
    Feb 12, 2013
    #3
    I want to automate and mac address change which otherwise have to be done manually in the terminal after every boot
     
  4. Peace macrumors Core

    Peace

    Joined:
    Apr 1, 2005
    Location:
    Space--The ONLY Frontier
    #4
    Out of curiosity why do you want to change the MAC address every time you boot ?
     
  5. MacRaccoon thread starter macrumors member

    Joined:
    Feb 12, 2013
    #5
    because I'm a criminal and it's better to be safe than sorry :)


    p.s.
    or I live in a jurisdiction where they have the ISPs identify you by that and the special forces raid your home in the middle of night just because you support the opposition of the currently ruling party. Take your pick :)
     
  6. hallux macrumors 68020

    hallux

    Joined:
    Apr 25, 2012
    #6
    The MAC address is coded in the network card, not so easy to change but you may be looking for MAC spoofing software.
     
  7. Peace macrumors Core

    Peace

    Joined:
    Apr 1, 2005
    Location:
    Space--The ONLY Frontier
    #7
    These same special forces allow you to connect to macrumors to ask how to change MAC addresses ? One would think if they're out to get you they would already have your Internet IP number.

    In other words you're late.
     
  8. Mr. Retrofire macrumors 601

    Mr. Retrofire

    Joined:
    Mar 2, 2010
    Location:
    www.emiliana.cl/en
    #8
    Is that a problem? And if yes, how big is it!?
     
  9. Mr. Retrofire macrumors 601

    Mr. Retrofire

    Joined:
    Mar 2, 2010
    Location:
    www.emiliana.cl/en
    #9
    The IP has nothing to do with the MAC-address.
     
  10. Peace macrumors Core

    Peace

    Joined:
    Apr 1, 2005
    Location:
    Space--The ONLY Frontier
    #10
    I didn't say it did.

    ;)
     
  11. switon, Feb 21, 2013
    Last edited: Feb 22, 2013

    switon macrumors 6502a

    Joined:
    Sep 10, 2012
    #11
    RE: random MAC addresses...

    Hi,

    I think you might be looking for the following commands:

    Code:
    #  The following command gets a random MAC address:
    RNDMAC=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
    echo $RNDMAC
    #  The following command reads the current MAC address:
    OLDMAC=`ifconfig en0 | grep ether | awk '{print $2}'`
    echo $OLDMAC
    #  The following command sets a random new MAC address:
    sudo ifconfig en0 ether `echo $RNDMAC`
    #  The following command resets to the original MAC address:
    sudo ifconfig en0 ether `echo $OLDMAC`
    
    The "openssl rand" command generates a random hexadecimal number formatted in the MAC address format. You can use this command to set a variable and then use the variable in the "ifconfig en0" command to set the MAC address, as shown. For some reason, in my hands anyway, the MAC address is not always reset and I have to generate a new random MAC address and then it is reset with the new random address. (You will need to use the interfaces appropriate for your machine, whether that is en0 or en1.) When I do this with my wireless, I am disconnected from my wireless AP since my wireless AP is set to only allow connection to certain MAC addresses. I then have to reset my MAC address back to the original (or add the new MAC address to my wireless router) before I can reattach to my wireless router.

    Of course, these commands can be included in a script that is executed at boot by launchd or other means. (You will need to remove the last command that resets the MAC address back to the original. And you will need to run this script with root privileges since root privileges are required to change the MAC address and you won't be interactively typing in your password for the "sudo"s.)

    Good luck,
    Switon

    P.S. I recommend that you record your current MAC address before resetting it to a new random one so that you can reset it back to its original value if need be.
     
  12. MacRaccoon thread starter macrumors member

    Joined:
    Feb 12, 2013
    #12
    You might want to google up "VPN" mate
    Still I might be a criminal as well! You never know with those things :)

    ----------


    Well now that's the super useful post I needed! Thank you mate! You are a ray of light in this thread :)
    Since i'm super new to OS X, can you just say few more words about this launchd thing that should execute the script upon boot?
     
  13. switon, Feb 22, 2013
    Last edited: Feb 22, 2013

    switon macrumors 6502a

    Joined:
    Sep 10, 2012
    #13
    RE: launchd, launchctl, launchd.plist, ...

    Hi MacRaccoon,

    First of all, thanks for the kind words. (The only really tricky thing is the sed command to insert the colons into the hexadecimal random number so that it is formatted like a MAC address -- and even this is not all that difficult: the sed first matches two digits, then returns them with a colon inserted after them, and then does this globally for the remainder of the hexadecimal number generated by openssl rand.)

    Secondly, launchd is the daemon that launches other daemons/agents. The Mac OS X kernel invokes launchd first upon boot before anything else is run, thus launchd is the tool that invokes all other processes during bootup. You don't execute launchd yourself, rather you use the launchctl utility to load and unload agents. So launchd is controlled by the launchctl command and it reads property lists (-.plist) in the /Users/<username>/Library/LaunchAgents, /Library/LaunchAgents, /Library/LaunchDaemons, /System/Library/LaunchAgents, and /System/Library/LaunchDaemons directories. Thus you can write a bash shell script to execute the openssl and ifconfig commands from my previous post. You then generate a plist (and load it with launchctl) in the /Library/LaunchAgents directory that executes this script upon boot. That's all there is to it. Of course, as I mentioned above, the ifconfig command must have root privileges in order to reset the MAC address, so the script will have to be executed with root privileges.

    All of these commands are documented in the manpages, so look at "man launchd", "man launchctl", "man launchd.plist", "man plist", "man scutil", etc. for further information and examples.

    Thirdly, there are other ways to accomplish this boot time reset of the MAC address. For instance, you could also use the Automator.app to execute the bash shell script containing the openssl and ifconfig commands whenever you login to your account.

    Good luck,
    Switon
     

Share This Page