0

How can I obtain and then change MAC address using objective-C? The solution was suggested only for iOS: How can I programmatically get the MAC address of an iphone

Community
  • 1
  • 1
Darius Miliauskas
  • 3,391
  • 4
  • 35
  • 53
  • See [this question](http://stackoverflow.com/questions/10593736/mac-address-from-interface-on-os-x-c) for reading the MAC address. See also [Change MAC address Cocoa - Objective-C](http://stackoverflow.com/questions/4825332/change-mac-address-cocoa-objective-c) of which your question is probably a duplicate. – Paul R Jan 06 '15 at 07:00
  • thanx, but it would be interesting how to achieve the goal without a shell script, just purely objective-C. – Darius Miliauskas Jan 06 '15 at 17:33

1 Answers1

1

This is setup a startup script to modify the MAC address each time you restart the computer.

#!/bin/sh
. /etc/rc.common

StartService () {
    networksetup -setairportpower en0 on
    networksetup -setairportpower en1 on
    /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
    /sbin/ifconfig en0 ether 00:`openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//'`
    /sbin/ifconfig en1 ether 00:`openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//'`
    networksetup -detectnewhardware
}

StopService () { return 0 }

RestartService () { return 0 }

RunService "$1"

Not directly using Objective-C but you can run a shell script from Obj-C using NSTask. More on that here.

I compiled this into a little installer a while back for a buddy. If you want the package, it's available here.

Community
  • 1
  • 1
davidcondrey
  • 34,416
  • 17
  • 114
  • 136