How can I programmatically get the connection status of OSX network services?

Posted by BigBrainz on Stack Overflow See other posts from Stack Overflow or by BigBrainz
Published on 2010-06-16T16:48:02Z Indexed on 2010/06/16 16:52 UTC
Read the original article Hit count: 162

Filed under:
|

In the OS X System Preferences, when I click on 'Network' I see a green dot by 'Ethernet', and red dots by 'AirPort' and 'FireWire'. This is because I turned off AirPort and FireWire, as I access networks and the Internet via Ethernet.

I need to programmatically determine which of these network services displayed in System Preferences have green dots and which have red dots. For Ethernet and FireWire the displayed status is 'Connected' or 'Not Connected', and for AirPort the displayed status is 'On' or 'Off'. Perhaps other network services have other status labels.

I have picked through all the plist files in '/Library/Preferences/SystemConfiguration', particularly 'preferences.plist' and 'NetworkInterfaces.plist'. I can get all sorts of information there, such as the Location set, network service order, proxy information (which is also important to my task), but I cannot find how to determine whether a given network service is on or off--the equivalent of having the green dot displayed.

I have also tried using System Configuration framework, specifically the SCNetworkConnectionGetStatus function, but all I get are invalid connection statuses.

Does anyone know how to actually retrieve this connection status information?

Thanks.

© Stack Overflow or respective owner

Related posts about osx

Related posts about system-programming