Lab: survey nearby Wi-Fi with iw or nmcli - bands, channels, signal and unknown BSSIDs
Read Linux wireless survey output from nmcli and iw, parse a synthetic iw-format scan fixture with Python to flag overlapping 2.4 GHz channels, low SNR and rogue BSSIDs, and inspect 802.11 management and PMF frames in tcpdump.
Contentsand lesson path
On this page
- Goal and setup
- Step 1: Survey visible networks with nmcli and iw
- Step 2: Predict and run the Python iw-scan and inventory audit
- Step 3: Inspect active client links, roaming events and association logs
- Step 4: Decode 802.11 Beacon and PMF Deauthentication frames in tcpdump
- Check your understanding
- Apply it
- Review prompt
Lessons of Wireless LAN Fundamentals
- Radio basics for network engineers: bands, channels, width and interference Concept · 20 min
- From beacon to data: scanning, association, roaming, band steering and Wi-Fi 6/6E/7 Concept · 20 min
- Securing Wi-Fi: WPA3, SAE, 802.1X/EAP, protected management frames and rogue APs Concept · 25 min
- Lab: survey nearby Wi-Fi with iw or nmcli - bands, channels, signal and unknown BSSIDs Lab · 25 min
- Worked example: a small-office WLAN design and a 'Wi-Fi is slow' ticket Worked example · 20 min
- Check: wireless design and troubleshooting scenarios Knowledge check · 8 questions
What you will learn
- Explain 802.11 operation - bands (2.4, 5 and 6 GHz), channels and widths, SSIDs and BSSIDs, association, roaming and band steering - and what Wi-Fi 6, 6E and 7 add.
- Plan channels and access-point placement and troubleshoot coverage, interference and association problems with signal metrics (RSSI, SNR) and client logs.
- Detect rogue and evil-twin access points by comparing surveyed BSSIDs with an authorised inventory, and explain how protected management frames (802.11w, mandatory with WPA3) stop deauthentication attacks.
01. Goal and setup
This lab proves three core operational principles on a Linux workstation: how nmcli and iw surface band, channel, signal, and Robust Security Network (RSN) attributes; why combining per-BSS beacon RSSI (iw scan) with channel noise floors (iw survey dump) exposes interference that raw signal bars hide; and how comparing surveyed BSSIDs against an AP base-MAC inventory plus inspecting 802.11 management frames separates legitimate corporate radios from evil twins and unprotected deauthentication attacks.
Seeing your corporate SSID (Corp) several times in one survey is normal when multiple dual-band or tri-band APs serve the floor. To distinguish a real Corp radio from an evil twin, you must verify its BSSID prefix against your AP hardware inventory, confirm its advertised authentication suite and PMF capabilities (MFPR), and verify its channel plan.
Environment note: our verification host (nmcli 1.36.6, Python 3.10.12, tcpdump 4.99.1, libpcap 1.10.1) has wired Ethernet (eno1) and no physical Wi-Fi radio. On your own Linux laptop with a wireless card (such as wlan0), you can run the nmcli and iw commands directly (sudo or CAP_NET_ADMIN is required to trigger fresh iw scan sweeps; iw dev wlan0 scan dump reads cached kernel results without root). Here, the live-radio outputs in Step 1 and Step 3 are marked Illustrative output matching NetworkManager nmcli and Linux wireless iw formatting, while the iw-scan Python auditor in Step 2 and the synthetic 802.11 .pcap + tcpdump inspection in Step 4 run for real on any Linux machine without root or Wi-Fi hardware.
02. Step 1: Survey visible networks with nmcli and iw
Start on a Wi-Fi-equipped Linux host by checking the wireless interface name (iw dev) and running nmcli for a compact summary table, followed by iw dev wlan0 scan and iw dev wlan0 survey dump for raw 802.11 Information Elements. Why use both tools? nmcli prints a quick table—and by default (--rescan auto) already triggers a fresh scan if NetworkManager's list is older than 30 seconds, while --rescan no reads the cache and --rescan yes forces a sweep. However, nmcli (devices.c) prints WPA3 only for SAE (WPA3-Personal) and prints WPA2 802.1X for both WPA2-Enterprise and WPA3-Enterprise, so it cannot verify whether an enterprise AP mandates PMF. iw prints every advertised RSN: authentication suite separated by spaces—such as IEEE 802.1X (AKM 1), FT/IEEE 802.1X (AKM 3, 802.11r fast transition), IEEE 802.1X/SHA-256 (AKM 5, usually advertised by WPA3-Enterprise alongside or without FT AKMs), IEEE 802.1X/SUITE-B-192 (192-bit mode), SAE (AKM 8), and PSK (AKM 2)—plus Management Frame Protection tokens (MFP-required and MFP-capable, corresponding to the 802.11 MFPR and MFPC capability bits), channel width (HT operation / VHT operation), and channel noise floors in survey dump (iw scan reports per-BSS beacon signal strength, not channel noise).
Read the nmcli columns carefully: IN-USE marks your active BSSID (*), CHAN and FREQ show channel number and centre frequency (2412 MHz = 2.4 GHz channel 1; 5180 MHz = 5 GHz channel 36), SIGNAL is NetworkManager's 0–100 quality score, and SECURITY lists advertised suites such as WPA2 802.1X, WPA3 (SAE), or WPA2.
nmcli -f IN-USE,BSSID,SSID,CHAN,FREQ,RATE,SIGNAL,SECURITY device wifi list
# Inspect RSN ciphers, PMF flags, widths, and channel noise floors with iw:
sudo iw dev wlan0 scan | \
grep -E "^BSS |freq:|signal:|SSID:|Authentication|Capabilities|secondary|width"
sudo iw dev wlan0 survey dump | grep -E "frequency:|noise:|channel busy"IN-USE BSSID SSID CHAN FREQ RATE SIGNAL SECURITY
* 00:11:22:33:44:10 Corp 36 5180 MHz 540 Mbit/s 84 WPA2 802.1X
00:11:22:33:44:11 Corp 1 2412 MHz 130 Mbit/s 88 WPA2 802.1X
00:11:22:33:44:21 Corp 6 2437 MHz 130 Mbit/s 72 WPA2 802.1X
DE:AD:BE:EF:99:01 Corp 4 2427 MHz 130 Mbit/s 96 WPA2
AA:BB:CC:11:22:33 GuestNet 4 2427 MHz 130 Mbit/s 62 WPA3Look at row four (DE:AD:BE:EF:99:01): it broadcasts Corp on 2.4 GHz channel 4 (2427 MHz) with WPA2 (personal PSK) instead of WPA2 802.1X, louder (96) than the legitimate lobby AP (88). And because nmcli prints WPA2 802.1X for both WPA2-Enterprise and WPA3-Enterprise, only inspecting the iw scan RSN: block confirms that 00:11:22:33:44:10 actually enforces MFP-required. Checking six rows by eye is easy, yet a real office scan can list fifty neighbour BSSes—so an automated parser prevents missed flags.
03. Step 2: Predict and run the Python iw-scan and inventory audit
Predict before running: Create survey_audit.py below, which parses a synthetic scan fixture matching Linux iw dev wlan0 scan format (SAMPLE_SCAN) and pairs it with scenario channel noise values (NOISE_DBM) matching iw dev wlan0 survey dump units. Before executing it, inspect 00:11:22:33:44:21 (freq: 2437.0, signal: -63.00 dBm, noise -79 dBm) and de:ad:be:ef:99:01 (freq: 2427.0, signal: -46.00 dBm, PSK, Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)). Predict the width, PMF state, SNR, and every alert flag each row will trigger, then run the script.
import re
AUTHORISED_PREFIXES = {"00:11:22:33:44": "Corp-Floor1"}
# Scenario channel noise values matching `iw dev wlan0 survey dump`
NOISE_DBM = {2412: -88, 2427: -84, 2437: -79, 5180: -92}
def freq_to_band_chan(freq):
if 2412 <= freq <= 2472:
return "2.4G", (freq - 2407) // 5
if 5180 <= freq <= 5885:
return "5G", (freq - 5000) // 5
if 5955 <= freq <= 7115:
return "6G", (freq - 5950) // 5
return "?", 0
def parse_iw_scan(text):
entries, cur, section = [], None, None
for raw in text.splitlines():
m = re.match(r"^BSS ([0-9a-f:]{17})\(", raw)
if m:
if cur:
entries.append(cur)
cur = {"bssid": m.group(1), "freq": 0, "signal": -100,
"ssid": "", "auth": "OPEN", "pmf": "NONE", "width": "20MHz"}
section = None
continue
if not cur:
continue
line = raw.strip()
if line.startswith("freq:"):
cur["freq"] = int(float(line.split()[1]))
elif line.startswith("signal:"):
cur["signal"] = int(float(line.split()[1]))
elif line.startswith("SSID:"):
cur["ssid"] = line[5:].strip()
elif line.startswith("RSN:"):
section = "rsn"
elif line.startswith("HT operation:"):
section = "ht"
elif line.startswith("VHT operation:"):
section = "vht"
elif section == "rsn" and line.startswith("* Authentication suites:"):
cur["auth"] = line.split(":", 1)[1].strip()
elif section == "rsn" and line.startswith("* Capabilities:"):
cur["pmf"] = "REQ" if "MFP-required" in line else (
"CAP" if "MFP-capable" in line else "NONE")
elif section == "ht" and line.startswith("* secondary channel offset:"):
if "above" in line or "below" in line:
cur["width"] = "40MHz"
elif section == "vht" and line.startswith("* channel width:"):
if "(80 MHz)" in line:
cur["width"] = "80MHz"
elif "(160 MHz)" in line:
cur["width"] = "160MHz"
if cur:
entries.append(cur)
return entries
SAMPLE_SCAN = """BSS 00:11:22:33:44:10(on wlan0) -- associated
\tfreq: 5180.0
\tsignal: -52.00 dBm
\tSSID: Corp
\tHT operation:
\t\t * primary channel: 36
\t\t * secondary channel offset: above
\tVHT operation:
\t\t * channel width: 1 (80 MHz)
\tRSN:\t * Version: 1
\t\t * Authentication suites: IEEE 802.1X FT/IEEE 802.1X
\t\t * Capabilities: 16-PTKSA-RC 1-GTKSA-RC MFP-required MFP-capable (0x00cc)
BSS 00:11:22:33:44:11(on wlan0)
\tfreq: 2412.0
\tsignal: -48.00 dBm
\tSSID: Corp
\tHT operation:
\t\t * primary channel: 1
\t\t * secondary channel offset: no secondary
\tRSN:\t * Version: 1
\t\t * Authentication suites: IEEE 802.1X/SHA-256
\t\t * Capabilities: 16-PTKSA-RC 1-GTKSA-RC MFP-required MFP-capable (0x00cc)
BSS 00:11:22:33:44:21(on wlan0)
\tfreq: 2437.0
\tsignal: -63.00 dBm
\tSSID: Corp
\tHT operation:
\t\t * primary channel: 6
\t\t * secondary channel offset: no secondary
\tRSN:\t * Version: 1
\t\t * Authentication suites: IEEE 802.1X
\t\t * Capabilities: 16-PTKSA-RC 1-GTKSA-RC MFP-required MFP-capable (0x00cc)
BSS de:ad:be:ef:99:01(on wlan0)
\tfreq: 2427.0
\tsignal: -46.00 dBm
\tSSID: Corp
\tHT operation:
\t\t * primary channel: 4
\t\t * secondary channel offset: no secondary
\tRSN:\t * Version: 1
\t\t * Authentication suites: PSK
\t\t * Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)
BSS aa:bb:cc:11:22:33(on wlan0)
\tfreq: 2427.0
\tsignal: -66.00 dBm
\tSSID: GuestNet
\tHT operation:
\t\t * primary channel: 4
\t\t * secondary channel offset: no secondary
\tRSN:\t * Version: 1
\t\t * Authentication suites: SAE
\t\t * Capabilities: 16-PTKSA-RC 1-GTKSA-RC MFP-required MFP-capable (0x00cc)
"""
for bss in parse_iw_scan(SAMPLE_SCAN):
band, ch = freq_to_band_chan(bss["freq"])
snr = bss["signal"] - NOISE_DBM.get(bss["freq"], -92)
suites = bss["auth"].split()
is_192bit = any("SUITE-B-192" in s for s in suites)
is_enterprise = is_192bit or any("802.1X" in s for s in suites)
flags = []
if bss["ssid"] == "Corp":
if bss["bssid"][:14] not in AUTHORISED_PREFIXES:
flags.append("ROGUE")
if not is_enterprise or bss["pmf"] != "REQ":
flags.append("WEAK_SEC")
if band == "2.4G" and ch not in (1, 6, 11):
flags.append("OVERLAP_2G")
if snr < 25:
flags.append(f"LOW_SNR({snr}dB)")
tags = ["192-bit"] if is_192bit else []
if flags:
status = ",".join(flags + tags)
elif tags:
status = "OK(" + ",".join(tags) + ")"
else:
status = "OK"
print(f"{bss['bssid']} {bss['ssid']:<8} ch={ch:>2}({band},{bss['width']:<5}) "
f"SNR={snr:>2}dB PMF={bss['pmf']:<4} {status}")python3 survey_audit.py00:11:22:33:44:10 Corp ch=36(5G,80MHz) SNR=40dB PMF=REQ OK
00:11:22:33:44:11 Corp ch= 1(2.4G,20MHz) SNR=40dB PMF=REQ OK
00:11:22:33:44:21 Corp ch= 6(2.4G,20MHz) SNR=16dB PMF=REQ LOW_SNR(16dB)
de:ad:be:ef:99:01 Corp ch= 4(2.4G,20MHz) SNR=38dB PMF=NONE ROGUE,WEAK_SEC,OVERLAP_2G
aa:bb:cc:11:22:33 GuestNet ch= 4(2.4G,20MHz) SNR=18dB PMF=REQ OVERLAP_2G,LOW_SNR(18dB)Compare the output against your prediction: 00:11:22:33:44:21 on channel 6 triggers LOW_SNR(16dB) because the two channel-4 radios raise channel 6's noise floor to -79 dBm, while de:ad:be:ef:99:01 trips three alerts simultaneously (ROGUE, WEAK_SEC, OVERLAP_2G). Notice that both 00:11:22:33:44:10 (IEEE 802.1X FT/IEEE 802.1X) and 00:11:22:33:44:11 (IEEE 802.1X/SHA-256) pass as valid enterprise APs because the parser checks whether any listed suite contains 802.1X (or SUITE-B-192 for 192-bit mode), and iw scan prints MFP-required and MFP-capable (not the raw 802.11 bit names MFPR/MFPC). Comparing the first five octets in AUTHORISED_PREFIXES assumes virtual BSSIDs share a 5-octet prefix—vendors using locally administered MAC bit flips (02:...) require listing each AP's exact BSSID range.
Simplification note: The width parser inspects only HT operation and VHT operation channel width: labels. Under current VHT signalling (802.11-2016 onwards), 160 MHz and 80+80 MHz BSSes report channel width: 1 (80 MHz) alongside a non-zero center freq segment 2, so this simplified parser reports 80MHz; likewise, 6 GHz widths live in HE Operation / EHT Operation blocks rather than HT/VHT operation, so 6 GHz entries default to 20MHz here.
04. Step 3: Inspect active client links, roaming events and association logs
Beacons in a survey tell you which BSSIDs exist nearby, not which BSSID, channel width, or Modulation and Coding Scheme (MCS) your laptop negotiated, or why a failed join dropped. On a Wi-Fi host, run iw dev wlan0 link for active link metrics, iw event -t while walking between rooms to measure roam latency (adding -f if you also want raw frame hex bytes), and journalctl -u NetworkManager -u wpa_supplicant to read authentication, association, and 4-Way Handshake errors.
iw dev wlan0 link
# In another terminal while walking between APs:
iw event -t
# Diagnose failed associations from client logs:
journalctl -u NetworkManager -u wpa_supplicant -n 15 --no-pager | fold -s -w 84Connected to 00:11:22:33:44:10 (on wlan0)
SSID: Corp
freq: 5180.0
RX: 14820 bytes (142 packets)
TX: 9410 bytes (98 packets)
signal: -52 dBm
rx bitrate: 433.3 MBit/s VHT-MCS 9 80MHz short GI VHT-NSS 1
tx bitrate: 390.0 MBit/s VHT-MCS 8 80MHz short GI VHT-NSS 1
--- iw event -t while roaming ---
1732700012.104120: wlan0 (phy #0): deauth a4:5e:60:11:22:33 -> 00:11:22:33:44:10
reason 3: Deauthenticated because sending station is leaving (or has left) the
IBSS or ESS
1732700012.112340: wlan0 (phy #0): auth 00:11:22:33:44:20 -> a4:5e:60:11:22:33
status: 0: Successful
1732700012.148410: wlan0 (phy #0): assoc 00:11:22:33:44:20 -> a4:5e:60:11:22:33
status: 0: Successful
1732700012.148902: wlan0 (phy #0): connected to 00:11:22:33:44:20
--- journalctl excerpt: Case A (PSK / 4-Way Handshake failure) ---
wpa_supplicant[842]: wlan0: Trying to associate with 00:11:22:33:44:11
(SSID='Corp-Guest' freq=2412 MHz)
wpa_supplicant[842]: wlan0: Associated with 00:11:22:33:44:11
wpa_supplicant[842]: wlan0: CTRL-EVENT-DISCONNECTED bssid=00:11:22:33:44:11
reason=15 locally_generated=1
wpa_supplicant[842]: wlan0: WPA: 4-Way Handshake failed - pre-shared key may be
incorrect
NetworkManager[790]: <warn> [1732700028.4102] device (wlan0): Activation: (wifi)
association took too long, failing activation
--- journalctl excerpt: Case B (802.1X EAP-TLS server certificate rejection) ---
wpa_supplicant[842]: wlan0: CTRL-EVENT-EAP-STARTED EAP authentication started
wpa_supplicant[842]: wlan0: CTRL-EVENT-EAP-TLS-CERT-ERROR reason=1 depth=0
subject='/CN=radius.evil.example' err='self-signed certificate'
wpa_supplicant[842]: wlan0: CTRL-EVENT-EAP-FAILURE EAP authentication failedWalk through the three outputs line by line:
- Roam time (
iw event):iwprints the sender first, so thedeauthline is the laptop leaving the old AP. Subtracting its timestamp (1732700012.104120) fromconnected(1732700012.148902), afterauthandassocboth complete withstatus: 0: Successful, gives a ~44.8 ms roam handoff—healthy for voice. - Case A (
reason=15and4-Way Handshake failed):Associated with 00:11:22:33:44:11proves RF signal, scanning, and 802.11 Open Authentication succeeded. The failure occurs afterward during key exchange (reason=15, 4-way handshake timeout): verify the passphrase (nmcli -s -g 802-11-wireless-security.psk connection show <name>, sincenmcliprints<hidden>unless-s/--show-secretsis passed), and check for WPA3-SAE or PMF cipher mismatches. - Case B (
CTRL-EVENT-EAP-TLS-CERT-ERROR): The laptop associated and started 802.1X/EAP, then aborted before sending user credentials because the RADIUS server presented an untrusted self-signed certificate (/CN=radius.evil.example). Compare the BSSID (iw dev wlan0 link) against your AP inventory to check for an evil twin, or verify the client's pinned RADIUS CA profile. (By contrast, if logs showCTRL-EVENT-ASSOC-REJECTbeforeAssociatedever appears, inspect AP PMF requirements or client rate/channel compatibility.)
05. Step 4: Decode 802.11 Beacon and PMF Deauthentication frames in tcpdump
To verify what an evil twin and a forged versus PMF-protected deauthentication frame look like on the wire without needing a monitor-mode card here, generate a deterministic four-frame Radiotap (DLT_IEEE802_11_RADIO) capture with make_pcap.py and decode it with tcpdump (Packet Capture & Analysis). Predict how tcpdump will display the unprotected forged deauth versus the fourth frame whose 802.11 Protected Frame bit (0x4000) is set.
import struct
def write_pcap(path, packets):
with open(path, "wb") as f:
# Little-endian pcap global header, DLT_IEEE802_11_RADIO = 127
f.write(struct.pack("<IHHIIII", 0xA1B2C3D4, 2, 4, 0, 0, 65535, 127))
for ts_sec, ts_usec, data in packets:
f.write(struct.pack("<IIII", ts_sec, ts_usec, len(data), len(data)))
f.write(data)
rt = struct.pack("<BBHI", 0, 0, 8, 0)
ap_5g = bytes.fromhex("001122334410")
evil = bytes.fromhex("deadbeef9901")
sta = bytes.fromhex("a45e60112233")
bcast = b"\xff" * 6
fixed = struct.pack("<QHH", 1000000, 100, 0x0411)
beacon_corp = (
rt + struct.pack("<HH", 0x0080, 0) + bcast + ap_5g + ap_5g
+ struct.pack("<H", 0x0010) + fixed + b"\x00\x04Corp\x03\x01\x24"
)
beacon_evil = (
rt + struct.pack("<HH", 0x0080, 0) + bcast + evil + evil
+ struct.pack("<H", 0x0020) + fixed + b"\x00\x04Corp\x03\x01\x04"
)
deauth_forged = (
rt + struct.pack("<HH", 0x00C0, 314) + sta + ap_5g + ap_5g
+ struct.pack("<H", 0x0030) + struct.pack("<H", 7)
)
deauth_pmf = (
rt + struct.pack("<HH", 0x40C0, 314) + sta + ap_5g + ap_5g
+ struct.pack("<H", 0x0040)
+ b"\x01\x00\x00\x20\x00\x00\x00\x00" # CCMP header (ExtIV=1)
+ b"\xaa\xbb" + b"\x11\x22\x33\x44\x55\x66\x77\x88"
)
write_pcap("wlan_mgmt_sample.pcap", [
(1732700000, 100000, beacon_corp),
(1732700000, 250000, beacon_evil),
(1732700001, 100000, deauth_forged),
(1732700002, 100000, deauth_pmf),
])
print("wrote wlan_mgmt_sample.pcap (4 frames)")python3 make_pcap.py
tcpdump -t -e -nn -r wlan_mgmt_sample.pcap 2>&1 | fold -s -w 84wrote wlan_mgmt_sample.pcap (4 frames)
reading from file wlan_mgmt_sample.pcap, link-type IEEE802_11_RADIO (802.11 plus
radiotap header), snapshot length 65535
BSSID:00:11:22:33:44:10 DA:ff:ff:ff:ff:ff:ff SA:00:11:22:33:44:10 Beacon (Corp) ESS
CH: 36, PRIVACY
BSSID:de:ad:be:ef:99:01 DA:ff:ff:ff:ff:ff:ff SA:de:ad:be:ef:99:01 Beacon (Corp) ESS
CH: 4, PRIVACY
BSSID:00:11:22:33:44:10 DA:a4:5e:60:11:22:33 SA:00:11:22:33:44:10 DeAuthentication:
Class 3 frame received from nonassociated STA
BSSID:00:11:22:33:44:10 DA:a4:5e:60:11:22:33 SA:00:11:22:33:44:10 DeAuthentication
IV: 1 Pad 20 KeyID 006. Check your understanding
07. Apply it
On your own Linux machine with a wireless interface, capture real output with sudo iw dev wlan0 scan > scan.txt and sudo iw dev wlan0 survey dump > survey.txt, adapt survey_audit.py to read scan.txt and extract noise: values directly from survey.txt, and tabulate every visible BSSID, band, channel, width, SNR, and RSN/PMF status.
Next, bring survey metrics, channel planning, PoE sizing, and security segmentation together in Worked example: a small-office WLAN design and a 'Wi-Fi is slow' ticket.
08. Review prompt
Explain why iw dev wlan0 scan must be paired with iw dev wlan0 survey dump to compute SNR, what MFP-required and MFP-capable inside an RSN: block (corresponding to 802.11 MFPR/MFPC bits) tell you about deauthentication resilience, how Associated plus reason=15 in wpa_supplicant narrows down a failed join, and what checks you run when nmcli device wifi list omits a newly booted AP.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.