我刚接触mac os x编程,现在有一个任务是编写一个小型实用程序,根据配置禁用无线或有线适配器。使用corewlan框架可以断开无线连接,如下所示:
CWInterface interface = [CWInterface interfaceWithName:@"en1"];
BOOL result = [interface setPower:NO error:&err];
它正在按预期工作。我需要类似的代码来禁用/断开以太网适配器。我研究了一下,可以使用ifconfig(如下所述):
sudo ifconfig en0 down
但是它需要管理员密码,我不想这样做。请建议一种没有根密码的替代编程方式来禁用以太网适配器。
我读到可以使用SCNetworkConfiguration,但不知道如何使用。请帮忙。
谢谢
networksetup -setnetworkserviceenabled Ethernet on
我从这里得到的:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/networksetup.8.html - thandasoru