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:
- Scans the Wi-Fi interface (wlan0by default) for nearby networks
- Filters out hidden or duplicate SSIDs
- Counts the number of unique SSIDs
- Outputs the count in a format compatible with NetBeez metrics
Prerequisites:
- Linux-based NetBeez agent with iwinstalled
- Wi-Fi interface capable of scanning (default: wlan0)
- sudoprivileges to run the scan
Expected Output:
- Number of unique Wi-Fi networks (SSIDs) detected
3. Script Code
#!/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!