简体   繁体   English

在OS X中使用Objective-C获取和更改MAC地址

[英]Obtaining and changing MAC address using objective-C in OS X

How can I obtain and then change MAC address using objective-C? 如何使用Objective-C获取并更改MAC地址? The solution was suggested only for iOS: How can I programmatically get the MAC address of an iphone 仅针对iOS建议解决方案: 如何以编程方式获取iPhone的MAC地址

This is setup a startup script to modify the MAC address each time you restart the computer. 这是一个启动脚本,用于在每次重新启动计算机时修改MAC地址。

#!/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. 不直接使用Objective-C,而是可以使用NSTask从Obj-C运行Shell脚本。 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 . 如果您需要该软件包, 请点击此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM