【问题标题】:Obtaining and changing MAC address using objective-C in OS X在 OS X 中使用 Objective-C 获取和更改 MAC 地址
【发布时间】:2015-03-03 19:38:28
【问题描述】:

如何使用 Objective-C 获取并更改 MAC 地址?该解决方案仅适用于 iOS:How can I programmatically get the MAC address of an iphone

【问题讨论】:

标签: objective-c macos osx-yosemite mac-address


【解决方案1】:

这是设置一个启动脚本,用于在每次重新启动计算机时修改 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"

不直接使用 Objective-C,但您可以使用 NSTask 从 Obj-C 运行 shell 脚本。 More on that here.

我不久前将它编译成一个小安装程序供朋友使用。如果你想要这个包,it's available here

【讨论】:

  • 这如何回答这个问题?
猜你喜欢
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 2020-05-20
  • 1970-01-01
  • 1970-01-01
  • 2013-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多