4

Is there an API, shell command or AppleScript for getting an accurate reading of the current WiFi strength in Mac OSX?

FYI I can also open a browser and use JavaScript if it has that value available.

What I'm trying to do is check WiFi strength for different spots in my kitchen or living room. I need to check WiFi strength for each spot. If it's low I move to a new spot. The WiFi bars that OSX displays is not enough data for me.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231

4 Answers4

4

Here's a simple Python script which uses the CoreWLAN framework:

#!/usr/bin/python

from AppKit import CWInterface

IFACE = 'en0'
NAME  = 'MyWifiNetwork'

interface      = CWInterface.interfaceWithName_(IFACE)
results, error = interface.scanForNetworksWithName_error_(NAME, None)

for result in results:
    print 'SSID:', result.ssid()
    print 'RSSI:', result.rssiValue()
robertklep
  • 198,204
  • 35
  • 394
  • 381
3

There is a built-in airport command which will do it. It's location is:

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

For convenience, you can create a link which will let you run the command from anywhere.

 sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport

To get info about the current wireless network

airport -I

http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/

Assuming you've created the link, an AppleScript that converts the value to percentage and displays a notification:

set wirelessRSSI to do shell script "airport -I | grep CtlRSSI | sed -e 's/^.*: //g'"
set wirelessStrength to (wirelessRSSI + 100) * 2
display notification "Wireless sigal quality: " & wirelessStrength & "%"
empedocle
  • 1,862
  • 1
  • 14
  • 25
  • I tried to run that command from the directory it's in and it says, `-bash: airport: command not found`. If I list the directory it says it's there, `ls Info.plist airport airportd.sb version.plist` – 1.21 gigawatts Jul 04 '15 at 06:53
  • I mean to say do I have to create an alias to the command for it work? If I change directories to, `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/` and then run `airport` it gives me that error. If I use `sudo ln -s ...` to create a sym link it works. Anyway, it looks like it will work if I can create a link to airport. – 1.21 gigawatts Jul 04 '15 at 08:20
  • Specifying a command alone will search for it in a specified list of directories to search, ('echo $PATH' to see them). If you want to run a command from the current directory, once you're in that folder: ./airport – empedocle Jul 04 '15 at 08:21
  • Adding the path doesn't seem to work for `airport` for some reason. I have to create a sym link for it to work. I can probably work around this. Just FYI. – 1.21 gigawatts Jul 04 '15 at 08:36
  • Check here for a way to add to the path only if a directory is not already there: http://superuser.com/a/39995 add it to ~/.bash_profile (OS X doesn't read .bashrc for interactive shells), and then to use it: pathadd … – empedocle Jul 04 '15 at 09:28
  • This is a little aged, but I wanted to warn that El Capitan (OS X 10.11.x) has the new "rootless" feature that prevents modifying critical parts of the OS. If you want to follow this answer's procedure, you must first disable rootless in the Recovery environment using `csrutil disable` in the Terminal. Otherwise you will need to follow [this answer here](http://stackoverflow.com/questions/33223457/mac-osx-el-capitan-airport-sym-link-not-permitted) to work around the layer of security – Kamikaze Rusher Jan 27 '16 at 00:55
  • you should link to `/usr/local/bin/airport` rather than `sbin`. `sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport` – rodvlopes Feb 09 '16 at 15:02
1

I must admit that I don't know whether OS X has information like a received strength indicator easily accessible.

What I can tell you from an RF communication's engineer's perspective is that the displayed signal strength is everything but accurate, and it's even less usable to really predict how well communication will work.

As you said, the bars aren't enough information for anyone -- and the fact that there are already five different amounts of bars you can have usually greatly exaggerates the accuracy with which these things are available to the operating system. WiFi quality is so much more than received signal strength that you can't directly map bars to quality. I really don't know why GUIs keep including that measure instead of e.g. a measure of how many packets get lost along the way (which is actually something that an OS can observer).

I assume you want to do something like "if WiFi A is weak, switch to WiFi B", or similar. I think the right way to do that is actually two steps up the OSI layer model, at least. I'd personally just set up a server somewhere on the internet that replies to UDP packets and is pingable. Then, you'd just use standard ping to figure out whether latency is still acceptable, and use short UDP to the server packets to figure out how much packet loss you see (you can do that via ping and ICMP, too, but that won't normally allow you to send a couple of hundred packets per second -- which is what I'd do periodically).

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • That's pretty close to what I'm trying to do. "Check WiFi strength. If WiFi is weak notify user to move to another spot. Check WiFi strength. If WiFi OK do nothing. Repeat". – 1.21 gigawatts Jun 15 '15 at 07:24
  • I like the idea of pinging a server and checking the latency. Can I setup a server on my router and ping that? Or a server on my local host and route it through the router? I'm familiar with ping, tracert and a few other shell commands but not enough to route it back through localhost. – 1.21 gigawatts Jun 15 '15 at 07:28
  • 1
    puh, that's a pretty good question. You can probably do that, if you have sufficient privileges to fiddle around deeply in your system. I'd just ping the router, instead, if I were you. It should be pretty easy to find the default router under OS X. You should try what OS X's ping has as minimum setting for `ping -i ` for non-super users. – Marcus Müller Jun 15 '15 at 07:37
  • btw, latency will not be so much different. What's interesting is the percentage of low-level packets that had to be re-transmitted. Under linux, you can figure something like that out via SYSFS, but I really don't know darwin or any of the OS X network stack. – Marcus Müller Jun 15 '15 at 07:40
0

This is an well-hidden gem. Just navigate in the Finder to the folder

/System/Library/CoreServices/Applications

and run the

Wireless Diagnostics.app

It has many builtin tools.

Before you click "Continue" (in the 1st window) you should check the "Window" menu for the available tools:

  • WiFi sniffer of an exact channel ⌘6
  • Performance analyser (signal/Noise) ⌘5
  • Wifi scanner (available networks) ⌘4
  • Logger of some protocols (like DHCP, DNS etc) ⌘3
  • Info about the connected WiFI ⌘2 (same as when you Alt-click on the menubar WiFi)

Reply about 1.21 Gigawatts concerns

About the above tools:

  • The report is collected only if you click the "continue" button in the 1st screen.
    • As i told above, you not need to click it.
    • You can use the tools without collecting any report.

About report sending:

  • The app warns you about the data collecting.
  • The report is placed into your desktop. (as a file called date_string.wdmon)
  • The app doesn't sends any part of the report to Apple automatically.
  • You can send it to apple, if want - me personally doesn't want too. :)
  • If the user is stupid enough to double-click on the report file (what triggers the report-sending), after he, reads the warnings on the 1st screen it is his own fault.
  • you can monitor yourself what outgoing connections are done

Summary:

  • you don't need even start the report collecting. (simply don't click the continue button)
  • you can use the tools without the report-collecting - they're available in the Window menu as I told it already in my answer.
  • don't double-click on the files if you don't know what's happens

Warning users about the data collection is a good thing. Thank you for your explicit warning.

clt60
  • 62,119
  • 17
  • 107
  • 194
  • It looks like when you use this you are agreeing to send a diagnostic report to Apple. No thanks. http://i.stack.imgur.com/VFEFz.png – 1.21 gigawatts Jul 04 '15 at 07:00
  • Thanks for clearing it up. I don't mean to spread any misinformation but as you said, "The report is collected only if you click the "continue" button in the 1st screen." I see now you can use it without clicking continue. I think it's somewhat deceptive on Apple's part. But I was able to click the red close button on the window and use it without that. – 1.21 gigawatts Jul 04 '15 at 08:09
  • Apparently you have to open one of the windows first before you can close the dialog with the "continue" button. Otherwise the app will close down. I chose Window > Info and then closed the dialog. – 1.21 gigawatts Jul 04 '15 at 08:40
  • @1.21gigawatts or just leave the 1st window as-is (don't click continue) and use the tools :) – clt60 Jul 04 '15 at 08:44