There is a lot of power available in Terminal, and if used correctly you can create some really interesting scripts and result. Today’s post is going to take advantage of some built in Airport frameworks to measure the strength of your connected Wi-Fi signal. Although you can download and use various different apps to do this, if you want a quick way measure the signal, to find the best place to put your laptop, or integrate into something like GeekTool. A quick Terminal script is what you need.
Your make is built up on various frameworks, essentially build in blocks. Within these building blocks your Mac has all of the usual features you see and use. However select frameworks allow you to extract certain bits of information. This is exactly what we are going to do, to measure signal strength. To do this open Terminal and type the following.
You have to be connected to a Wireless signal. The output will look similar to the following:
op mode: station
802.11 auth: open
link auth: none
Most of the data is self explanatory. ‘agrCtlRSSI’ is the signal strength, we will want to get this as high as possible. This is the value we will use later on, ‘agrCtlNoise’ is the noise on your Wi-Fi signal you want this as low as possible. Finally, ‘maxRate’ is the maximum rate at which your Wi-Fi signal can run at, and ‘lastTxRate’ is the last transmitted rate. These two values will probably not change.
If you are interested you can also use this Terminal command to scan the airwaves for other Wi-Fi signals to connect to.
A Live Scanner
At the moment, using the first command to find the best signal is a bit bulky. The amount of information returned is too much. By placing it into a little loop and picking the right bit of information, it will return just the signal strength. As a result the information returned can easily be used to pick the right spot for your laptop. You simply walk around with your laptop and watch as the signal will rise and fall. [via macosxhints]
while x=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI; sleep 0.5; done
This little script will query the Airport as previously mentioned and pull out the signal strength part. Every half a second it will repeat. The results will look something like the following:
If you want the list to populate quicker, change 0.5 to something smaller. If you want a longer pause between the lines updating put in a higher value. To stop the output press Control + C and you be returned to the command line. If you want to view the noise associated with the Wi-Fi signal, type the following:
while x=1; do /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlNoise; sleep 0.1; done
Very useful and very interesting. If you want to use the command line in a different bash script or in something like GeekTool you only need to type the following.
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep CtlRSSI
There you go. Have a play around and see where to place your laptop for the best Wi-Fi result. Its a simple command but very useful. If you have any comments or tips relating to this command please let me know in the comments. If you are interested in reading more about Wi-Fi I recommend The Book of Wireless from Amazon.