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.
The green and red dots in the Control pannel generally correlate to the the output of the
ifconfigcommand on OSX.Typically and it can vary from computer to computer,
en0will be the ethernet port anden1the airport. (At least on all the Macbook pros I use)It looks like you can use ifconfig -m to get information about supported media.
$ ifconfig -m en0 en0: flags=8863 mtu 1500 ether (redacted) media: autoselect status: inactive supported media: media autoselect media 10baseT/UTP mediaopt half-duplex media 10baseT/UTP mediaopt full-duplex media 10baseT/UTP mediaopt full-duplex mediaopt hw-loopback media 10baseT/UTP mediaopt full-duplex mediaopt flow-control media 100baseTX mediaopt half-duplex media 100baseTX mediaopt full-duplex media 100baseTX mediaopt full-duplex mediaopt hw-loopback media 100baseTX mediaopt full-duplex mediaopt flow-control media 1000baseT mediaopt full-duplex media 1000baseT mediaopt full-duplex mediaopt hw-loopback media 1000baseT mediaopt full-duplex mediaopt flow-control media noneSeeing 10xxbaseT is usually a good sign it’s ethernet.
Wireless doesn’t seem to report any supported media.
The man page for ifconfig has a ton of information but there may be some system libraries for programatically accessing this information that I’m unaware of but this should get you started.