# Wi-Fi SSID Count Scan Script

**URL:** <https://community.netbeez.net/t/wi-fi-ssid-count-scan-script/300>\
**Category:** Custom Commands\
**Created:** [August 13, 2025, 9:17am UTC](https://community.netbeez.net/t/wi-fi-ssid-count-scan-script/300 "2025-08-13T09:17:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefano](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@stefano](https://community.netbeez.net/u/stefano)\
**Post date:** [August 13, 2025, 9:17am UTC](https://community.netbeez.net/t/wi-fi-ssid-count-scan-script/300/1 "2025-08-13T09:17:12Z")

</div>

## 1. Introduction

For network engineers and administrators, knowing how many Wi-Fi networks are nearby can be useful for interference analysis, troubleshooting, or coverage planning.  
This Bash script scans the Wi-Fi interface, counts the number of unique SSIDs, and reports the result in a NetBeez-friendly format.

**Example Use Cases:**

- Identify Wi-Fi congestion in the local area
- Monitor the number of neighboring networks over time
- Assist in selecting optimal channels for APs

* * *

## 2. Overview of the Script

This Bash script:

1. Scans the Wi-Fi interface (`wlan0` by default) for nearby networks
2. Filters out hidden or duplicate SSIDs
3. Counts the number of unique SSIDs
4. Outputs the count in a format compatible with NetBeez metrics

**Prerequisites:**

- Linux-based NetBeez agent with `iw` installed
- Wi-Fi interface capable of scanning (default: `wlan0`)
- `sudo` privileges to run the scan

**Expected Output:**

- Number of unique Wi-Fi networks (SSIDs) detected

* * *

## 3. Script Code

```bash
#!/usr/bin/env bash

# Perform WiFi scan and count SSIDs
scan_output=$(sudo iw wlan0 scan 2>/dev/null)

# Check if scan was successful
if [$? -ne 0]; then
    echo "ssids_num=0"
    exit 1
fi

# Count unique SSIDs (filter out hidden networks and duplicates)
ssids=$(echo "$scan_output" | grep -E "^\s*SSID:" | grep -v "SSID: $" | sort -u | wc -l)

echo "ssids_num=$ssids"

```

## 4. Sample Output

`ssids_num=8 `

* * *

## 5. Closing Remarks

This script provides a quick and automated way to monitor nearby Wi-Fi networks from a NetBeez agent. It is particularly useful for detecting interference or changes in the wireless environment over time.

**Extensions you could try:**

- Log SSID counts periodically for trend analysis

- Record SSID names for further reporting

- Combine with signal strength metrics to identify weak APs

Share your improvements in the comments so the community can benefit!
