4

I'm doing a project regarding RSSI and I have to retrieve the signal level of a particular WiFi SSID that I'm working on using the Linux command line.

I've made use of the iwlist scanning command but I just couldn't get it to display the values that I want by using grep to print only the SSID name, quality and signal level.

Commands that I've tried that didn't give me the results I wanted:

  1. iwlist INTERFACE scanning essid SpecificESSID | grep Signal

  2. iwlist INTERFACE scanning essid SpecificESSID | grep ESSID,Signal

  3. iwlist INTERFACE scan | grep 'ESSID:"SpecificESSID"\|Signal level' - This almost worked but it displayed other networks' signal level as well and I only need one specific network information.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Terence Chew
  • 43
  • 1
  • 1
  • 3

1 Answers1

8

First, iwlist is the old command, there's the newer iw command with more features.

If the "SSID you are working on" is the access point (AP) you are currently connected to, use

iw wlan0 station dump

pick the value(s) you are interested in (say, average signal strength), and then something like

iw wlan0 station dump | grep 'signal avg:'

For the currently connected AP, you actually have more detailed information than for all APs.

If you want signal strength for all visible APs, do something like

iw wlan0 scan | egrep 'SSID|signal'

You can post-process this for SSIDs you are interested in. Say you want SSID1 and SSID2, then you can do

iw wlan0 scan | egrep 'SSID|signal' | egrep -B1 'SSID1|SSID2'

The -B1 displays the line before the match, because in the scanning output, the signal strength comes before the SSID.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
dirkt
  • 31,679
  • 3
  • 40
  • 73
  • Thanks for guiding me. The last command helped and saved me all the troubles from looking around the web aimlessly. – Terence Chew Mar 29 '18 at 05:41
  • The note shown at the end of the output of `iw` command: `Do NOT screenscrape this tool, we don't consider its output stable.` is a bit unsettling. – nurettin Dec 01 '19 at 13:17
  • 1
    @nurettin: That comment has been there for years... and even if they actually do change the format, adapting the script isn't difficult. And if you really really need to make sure it's stable, copy the binary and use it with a new name, so it doesn't get updated by the package manager. Or read the source code and write your own... – dirkt Dec 01 '19 at 15:45
  • This limits the scan to a specific SSID: `iw wlp3s0 scan ssid the_specific_ssid` – Matthias Braun Dec 08 '22 at 19:40
  • @MatthiasBraun: I see that option, but when using it I still see all SSIDs. – dangeroushobo Jun 08 '23 at 14:59
  • @dangeroushobo: You're right, I misinterpreted `iw`'s documentation. [Here's](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894316#msg20) an explanation on how it works: "However, this does *not* mean that it will also *show* only networks with the given SSID(s), it merely means that the underlying driver only *sends probes* for those SSID(s). All other networks discovered at the same time, by passively picking up other beacons or probe responses, or perhaps even by a previous scan, will still be shown." [Here's](https://bugzilla.redhat.com/show_bug.cgi?id=1300205) another bug report. – Matthias Braun Jun 08 '23 at 22:14
  • Try this to see only a certain SSID: `mkdir /tmp/iw_scan_single_ssid; cd "$_"; sudo iw wlp3s0 scan | csplit --elide-empty-files - '/^BSS/' '{*}'; grep -l 'your SSID goes here' * | xargs -d '\n' cat`. Some pointers: [csplit](https://www.gnu.org/software/coreutils/manual/html_node/csplit-invocation.html). [`mkdir abc; cd "$_"`](https://stackoverflow.com/questions/14136635/one-command-to-create-and-change-directory#26721700). [Print entire file when grep matches](https://stackoverflow.com/questions/49390302/grep-to-print-all-file-content) – Matthias Braun Jun 08 '23 at 22:18
  • This should be the equivalent with [`awk`](https://manpages.org/awk): `sudo iw wlp3s0 scan | awk -v RS='(^|\n)BSS' '/SSID: your SSID goes here/ { print "BSS" $0 }'`. With `RS='(^|\n)BSS'` we set the [record separator](https://www.gnu.org/software/gawk/manual/html_node/awk-split-records.html) to "BSS" with either the start of the string (`^`) or a newline in front of it. This splits up `iw`'s scan results into blocks of basic service sets. If the record contains `SSID: ...` we print the BSS block. Since the record separator `(^|\n)BSS` is not part of the output, we add that before the block. – Matthias Braun Jun 09 '23 at 21:41