I am new to mac os x programming and just got an assignment to write small utility that disable either wireless or wired adapter based on configuration. I was able to disconnect wireless using corewlan framework like :
CWInterface interface = [CWInterface interfaceWithName:@"en1"];
BOOL result = [interface setPower:NO error:&err];
and it is working as expected. I need similar code to disable/disconnect ethernet adapter. I researched that ifconfig (as mentioned below can be used):
sudo ifconfig en0 down
but it require admin password and that i don’t want to do. Please suggest an alternative programatic way to disable ethernet adapter without root password.
I read that SCNetworkConfiguration can be used but don’t know how to use it. Please help.
Thanks
You cannot shut off network interfaces without having admin access (i.e. that’s why the padlock is there in the Network Preference Pane). Think of it this way… you would not want non-admin users on any public machine being able to turn off the network arbitrarily.
For my own apps where I also disable Ethernet & WiFi, I have to get privileges to launch a separate tool in order to run stuff from the SystemConfiguration framework as admin.