Solely to round out the answers (not to suggest that there's something wrong with the other answers, but only to show there is another way to do it), I'll throw out this:
Use the airport
command found at:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
which has been there since at least 10.6. (I always link it to /usr/local/bin/
whenever I am setting up a new Mac).
One of the benefits of the airport
command is that you don't have to know what the interface is, because:
"If an interface is not specified, airport will use the first AirPort interface on the system."
Therefore, if I run this command:
airport prefs 2>&1
I get this output:
AirPort preferences for en1:
DisconnectOnLogout=NO
Unable to retrieve JoinMode
Unable to retrieve JoinModeFallback
RememberRecentNetworks=NO
RequireAdminIBSS=NO
RequireAdminNetworkChange=NO
RequireAdminPowerToggle=NO
WoWEnabled=YES
which means that I can get the port/device name by looking for the last word on the first line, minus the colon.
airport prefs 2>&1 | awk -F' ' '/for/{print $NF}' | tr -d ':'