airport - the Little Known Command Line Wireless Utility
January 18th, 2007 - Mac OS X, Tips & Tricks, Command Line
Strangely hidden from the casual user is a spiffy command line utility that allows you to view, configure, and troubleshoot your Mac’s wireless connection. It doesn’t appear to be well documented, and judging by the obscure location of the command, Apple probably didn’t think it would be too useful for the average Mac user. But the hidden command line airport tool is very useful indeed, so here is how to access it, and how you can use it too.
The first thing you’ll want to do is create a symbolic link to the airport command, because it is situated in a very inconvenient location for quick usage. Doing so is very easy, in the Terminal type the following:
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
The above may be a bit hard to read on some browsers, so alternatively you can use the following (it does the same thing, just split into two commands):
$ cd /usr/sbin
$ sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
This will prompt you for a root password, enter it and hit return.
Yes, that giant cryptic path through the depths of OS X is where Apple hid the wonderful airport utility, but by running the above command you have just linked that long path to the much shorter ‘airport’ , great. You’ll probably find the -I flag and -S flags to be most useful and informative, so type airport -I at the Terminal prompt, which will return something like the following:
$ airport -I
commQuality: 75
rawQuality: 59
avgSignalLevel: -40
avgNoiseLevel: -97
linkStatus: ESS
portType: Client
lastTxRate: 11
maxRate: 11
lastAssocStatus: 1
BSSID: 00:06:5b:2a:37:10
SSID: OSXNetwork
Security: none
$
Displayed is detailed information on signal quality, noise, security, and other WiFi network attributes. The airport command is more powerful than just being able to list information on the current wireless network though, you can actually manually adjust many settings and troubleshoot too. While there is no manual page for the airport command, attaching the -h command to it will issue a brief list of flags and explanations of their function. Enjoy!
Social bookmarks:
- del.icio.us | Digg it | Furl | ma.gnolia | Netscape | reddit | StumbleUpon | Yahoo MyWeb |
Comments:
Comments: 23
Comment from anon
Time: January 18, 2007, 9:04 pm
That’s a great tip - nice find, OSXDaily.
Comment from Shlomo
Time: January 21, 2007, 12:50 am
Awesome! Thanks for the cool util
Comment from Alpharetta
Time: January 24, 2007, 5:39 pm
HOLY MOLY BEST EVER!!
Comment from Cailin Coilleach
Time: February 1, 2007, 11:19 am
Here’s another vote for “holy moly”! Now I’ll have to go dig through the system for any and all hidden executable binaries. Who knows what else is hidden?!
Comment from nate
Time: February 3, 2007, 9:09 am
There’s documentation available, just type:
$airport –help
Its not too informative, but there’s some info there.
Comment from KB
Time: February 19, 2007, 7:10 am
This tip has ended hours of pulling my hair out. I’d been having trouble with my Mac mini computer automatically joining random wireless networks rather than the *one* network I’d ever want it to join … and this is despite using Network Preferences to configure Airport to join only preferred networks by default; to ask before joining an open network; and to require an admin password to change wireless networks.
I wrote a script which runs “airport -I” to notice when I’m not connected to my desired network and then to run airport –associate to rejoin. I’m using cron to run this script every few minutes, and my logs show this fixing things several times a day so far.
This also allowed me to add a StartupItem so that I can have my mini (which runs my web site, etc.) join the correct network on startup before anyone even logs in. Before I found this tip, I couldn’t find a way to get my mini to join any wireless network until I logged in.
Comment from anon
Time: March 5, 2007, 7:43 am
Anyone know how to use this command line util to turn airport off?
Comment from Mifilte
Time: October 19, 2007, 10:36 am
airport -z unjoins all networks
Comment from AirPorter
Time: November 5, 2007, 10:17 am
To actually turn airport off, you simply take the AirPort network interface down like so:
sudo ifconfig en1 down
Comment from anon
Time: November 6, 2007, 8:45 pm
Still works in Leo! (That’s ‘cool’ for Leopard, Googlebots)
Comment from tuco
Time: November 19, 2007, 11:21 am
How do you spoof your MAC address on a PowerBook wireless card?
$ ifconfig lladdr xx:xx:xx:xx:xx
works on /dev/en0 but no luck on /dev/en1.
Comment from Marco
Time: November 21, 2007, 8:33 pm
Hi man!
This command is very useful, but I have a question:
airport -I gives info about signal strenght with the line
avgSignalLevel: -40
I think this value is in dB.
When you type airport -s, you have the list of all networks avaiable, but which is the parameter which identifies the signal strenght? I think it could be
Sig 56
But it is in Watt or what?
Comment from David
Time: December 4, 2007, 8:30 am
Is there a way to use this utility to maintain a wireless connection? At work, I use my MacBook Pro with a wireless network (a building full of PC’s) that, when idle for very long, breaks the wireless connection, requiring logging on again. I have been unable to find a “stay connected” utilitiy for wireless like we used to have with modems.
Thanks
Comment from OS X Daily Mac Tips - Paul
Time: December 4, 2007, 9:20 am
@David
I’ve run into similar problems before with some networks that seem to have a strict policy on idling. To circumvent this, try constantly pinging a server (either on the network or outside). To do this, open your Terminal (spotlight for Terminal) and type the following:
ping google.com
instead of google.com you can use your LAN router or whatever other IP (10.1.1.1). Just let that run in the background while you’re doing things, and your connection should stay alive since small amounts of data are constantly being sent.
Hope that helps,
Paul
Comment from Ryan
Time: January 9, 2008, 12:17 pm
Someone please help me. I have tried to use this command to associate via BSSID and cannot get it to work. So far as I can tell, all the other commands work fine. I have several routers that have the same SSID and I need to be able to specify which one to connect to. Can someone help me?
Comment from vchoi
Time: January 21, 2008, 10:38 am
Very nice command. Saved my day as I need to troubleshoot problems in my wireless network.
Pingback from workaround for mac os x lost wifi connection | olpa, OSS developer
Time: January 29, 2008, 8:13 pm
[…] As a temporary solution, I found how to re-connect from a command line, thanks to the blog article “airport - the Little Known Command Line Wireless Utility”. I’ve created the file reconnect.sh and run it when required: […]
Comment from Ricardo
Time: February 9, 2008, 10:05 am
I have do this implementation in python to automatically reconnect to my wireless if disconnected:
import os
import time
import logging
CHECK_PERIOD_IN_SECONDS = 60
TEMPFILE = “connection-info.txt”
KEYWORD = “MyPlace”
LOGFILE = “airport-reconnect.log”
def is_connected():
# Generate connection info
os.system(”/usr/sbin/airport -I >” + TEMPFILE)
# Read connection info
f = open(TEMPFILE, “r”)
data = f.read()
f.close()
# Check
return KEYWORD in data
def connect():
os.system(”/usr/sbin/airport -a”)
logging.info(”Re-connected.”)
if __name__ == “__main__”:
# Logger
try: os.remove(LOGFILE)
except: pass
logging.basicConfig(level=logging.DEBUG,
format=’%(asctime)s %(levelname)-8s %(message)s’,
filename=LOGFILE,
filemode=’w')
# Loop
while True:
if not is_connected():
connect()
time.sleep(CHECK_PERIOD_IN_SECONDS)
Comment from walter
Time: February 27, 2008, 8:37 am
I’m looking for a way to automate the wireless configurations of hundreds of laptops in my school.
Can anyone point me to a solution?
I’m configuring the wireless using peap with mschap v2 and a certificate, all the laptops are macbooks osx 10.4
Thanks.
Comment from Weja
Time: March 14, 2008, 2:49 pm
Guys I really need your help ASAP
I have this huge problem in turning my AirPort on. I cant select the Airport’s checkbox in my network port configurations and I dont know why??? I can select and deselect the rest of the ports (bluetooth, internal modem, built in ethernet, etc) but NOT the AirPort!!!!
HELP MEEEEEEEEEEEEE
Thanks
Pingback from foodworms.net » Blog Archive » RubyCocoa: a simple wireless signal strength meter
Time: April 4, 2008, 12:35 pm
[…] Next I remembered a very useful post about How to get the wireless signal strenght from you airport and I decided to put togheter my (very small) knowledges of RubyCocoa to create a script that make your mac to work as an hot spot detector. […]
Pingback from apple command line wireless tool at thought cruft
Time: April 10, 2008, 4:34 pm
[…] via: airport - the Little Known Command Line Wireless Utility - OS X Daily Search […]
Pingback from The Cave » Blog Archive » ‘airport’
Time: April 13, 2008, 6:27 pm
[…] The Little Known Command Line Wireless Utility […]

Write a comment