Mac OS X,  Mass Deployment

Managing Airport Settings from the Command Line

From time to time we will end up writing shell scripts that do a number of tasks with airport interfaces in Mac OS X, including automatically detecting networks and disabling the card based on TCP/IP settings/location, querying signal strength for positioning of WAPs and joining specific wireless networks.  As such, a couple of commands keep coming up, since the airport card in a Mac can be controlled in a number of ways from the command line.  First and foremost – it can be enabled and disabled using the networksetup command, located in /usr/sbin.  The option to use with the command is -setairportpower which is boolean as on or off.  So to turn the airport on you would use the following command:

networksetup -setairportpower on

Or to turn it off you would use the following command:

networksetup -setairportpower off

If you want to know, from the command line, whether or not the airport is enabled, you can use the following command:

networksetup -getairportpower

Aside from controlling the status of whether the airport card is enabled and querying for whether or not it is enabled, you can also use networksetup to set the wireless network that the airport card joins.  This is done using the -setairportnetwork option, followed by the name of the network and then the password to be used.  For example, if you have a network called nightcrawler with a password of Password1 then you can use the following command to join that network:

networksetup -setairportnetwork nightcrawler Password1

If you would like to simply obtain information about which wireless network that a system has been joined to you can use the -getairportnetwork option with networksetup.  

In addition to setting up the airport network, you can also do a variety of tasks with enabling the network service, disabling, naming and controlling settings (including TCP/IP settings) for the network service, which I explained how to do in this article over on Xsanity.  

There are also commands that can help with troubleshooting wireless networking issues included with Mac OS X.  One of the most helpful is the airport command itself, located in the /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources directory.  Since you know how to join a wireless network using networksetup, as described earlier in this article, you might next want to go ahead and figure out the wireless networks available to your computer.  You can use the airport command for this.  Simply run it with the -s option, which should show output similar to the following:

 

SSID BSSID             RSSI CHANNEL SECURITY (auth/unicast/group)

crappywireless 00:15:05:35:92:4d -36  9       NONE

 City of Minneapolis Public WiFi 00:0d:67:0a:a4:d3 -69  6       NONE

 

One thing to note about the above output is that RSSI (signal strength) is listed here, as well as the channel that the wireless network is using.  Channels should be as unique as possible, and looking at this information can be a great and quick way to determine if you have another network with the same channel nearby.  Unless you hack your neighbors wireless network then it’s likely easiest to just change your own.  However, if you do change yours and you’re using WDS then prepare to have a broken WDS…

Another of the most basic tasks this command can fulfill is the ability to simply report statistics about the 802.11 card.  This can be done by using the -I option, for example:

airport -I

This command provides a ton of feedback, seen as follows:

 

agrCtlRSSI: -39

agrExtRSSI: 0

agrCtlNoise: -99

agrExtNoise: 0

state: running

op mode: station 

lastTxRate: 130

maxRate: 130

lastAssocStatus: 0

802.11 auth: open

link auth: wpa2-psk

BSSID: 0:1b:63:2a:ef:e6

SSID: shadowcat

MCS: 15

channel: 2

The first two indicators represent the RSSI.  RSSI refers to the Received Signal Strength Indication, or the amount of juice the radio signal actually has.  Next is the amount of noise.  The more noise in the radio signal, the more static it would provide if it were audio, so it’s safe to assume this means the more dropped packets, or packet collisions during transmission.  Next, state is fairly self explanatory and then op mode, which describes whether you’re subscribed to a wireless network or have created your own.  This is followed by rate, or the speed with which the connection can allow (for example, if the value here is 54 then it’s 802.11g).  Following that is whether the 802.11 network requires auth and if so what form of auth is required.  Next the base station ID (BSSID), which is the number printed on the bottom of the airport itself (for most models).  Next, the SSID, or name of the wireless network that you’re joined to (keep in mind SSIDs can be suppressed).  Finally, there is the channel of the network you’re currently joined to.

You can also use the -c option to set the channel on a card, which I have rarely done.  While I typically use networksetup to join networks, you can also join a network using the airport command, followed by the -A option and the –bssid (base station ID) and –password for the password.  In order to aid in scripting Airport information for graphs and things of that nature, the -r option can be used to set the number of times that the command will run in a loop.  Finally, you can use the -z option to simply unjoin a network.

Finally, for those who will be deploying airport settings en masse, you’ll be interested to know that you can also edit the plist files directly, with information about wireless networks tracked in /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist.  The passwords to join said networks, which are stored in the file as password IDs are then housed in the system keychain.  Network configuration for those same interfaces are configureable by editing com.apple.network.identification.plist in /Library/Preferences/SystemConfiguration.