Skip to content

Instantly share code, notes, and snippets.

@nigelkersten
Created October 18, 2010 22:17
Show Gist options
  • Save nigelkersten/633191 to your computer and use it in GitHub Desktop.
Save nigelkersten/633191 to your computer and use it in GitHub Desktop.
SystemConfig examples with Python on OS X
These links aren't always easy to find.
http://developer.apple.com/library/mac/#documentation/Networking/Reference/SCNetworkConfiguration/Reference/reference.html
http://developer.apple.com/library/mac/#documentation/Networking/Reference/SCPreferences/Reference/reference.html
nigelk$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from SystemConfiguration import *
>>> prefs = SCPreferencesCreate(None, "foo", None)
>>> services = SCNetworkServiceCopyAll(prefs)
>>> for service in services:
... print SCNetworkServiceGetName(service)
...
PdaNet
Ethernet
Bluetooth DUN
FireWire
Novatel Wireless CDMA MC760 SPRINT
FireWire
Ethernet
Sprint u760
AirPort
gvpn
Bluetooth DUN
AirPort
>>> for service in SCNetworkServiceCopyAll(prefs):
... if SCNetworkServiceGetName(service) == "AirPort":
... airport_service = service
>>> airport_interface = SCNetworkServiceGetInterface(airport_service)
>>> print airport_interface
<SCNetworkInterface 0x10370d570 [0x7fff70e45f20]> {type = IEEE80211, entity_device = en1, entity_type = Ethernet, name = AirPort, name(l) = AirPort, address = 0x00236c7fe3c5, builtin = TRUE, location = , path = IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/RP04@15/IOPCI2PCIBridge/ARPT@0/AirPort_Brcm43xx/AirPort_Brcm43xxInterface, type = 6, unit = 1, order = 11, prefs = 0x1002897c0, service = 8B7BD908-7BEC-4D5D-BAD5-0CCB761FF760}
>>> print SCNetworkInterfaceGetConfiguration(airport_interface)
{
DisconnectOnLogout = 0;
JoinMode = Automatic;
JoinModeFallback = (
Prompt
);
PowerEnabled = 1;
PreferredNetworks = (
{
"SSID_STR" = REDRUM;
SecurityType = "WPA Personal";
"Unique Network ID" = "225662B5-168C-4610-A594-6E86D08887E2";
"Unique Password ID" = "26C0FFE2-43D2-42DE-B2EE-AA6BD2B8DDED";
}
);
RememberRecentNetworks = 1;
RequireAdminIBSS = 0;
RequireAdminNetworkChange = 0;
RequireAdminPowerToggle = 0;
}
# Finding the actual IP is something I can't quite remember how to do right now :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment