Re: How to show ALL nearby Wi-Fi AP's BSSID every time

Marian <[email protected]>
Newsgroups alt.comp.os.windows-10,alt.comp.os.windows-11,alt.comp.microsoft.windows
Organization BWH Usenet Archive (https://usenet.blueworldhosting.com)
Message-ID <[email protected]>
Marian wrote:
> It found about a score of APs, but with different amounts in each scan.

I added a better output summary. I tried to get a RSSI histogram, 
but it was just too cumbersome; so I backed off & just added counts.

It's a bummer that Windows isn't reliable in outputting all the 
access points nearby in a single command, but this works reasonably.

 @echo off
 REM This is C:\data\sys\batch\netscan.bat version 2p1
 REM Logs the fullest list possible of all nearby Wi-Fi APs
 REM v1p0 20251213 outputs wifi adapter AP cache to a log file
 REM v1p1 20251213 disconnects/reconnects Wi-Fi, then outputs AP cache
 REM v1p2 20251213 captures multiple snapshots for the fullest AP list
 REM v1p3 20251213 captures multiple AP scans with timestamps for each
 REM v1p4 20251213 build a consolidated summary of the full list of AP's 
 REM v1p5 20251213 count the unique BSSIDs and SSIDs found in the AP scan
 REM v1p6 20251213 add a summary of BSSIDs and SSIDs found per scan
 REM v1p7 20251213 add a signal-strength histogram via PowerShell
 REM v1p8 20251213 separate scan results into files for better counts
 REM v1p9 20251213 tried to create histogram using PowerShell but failed
 REM v2p0 20251213 reverted to 1p6 and created tmp files to fix counts
 REM v2p1 20251213 added per-scan BSSID counts along with the SSID counts
 REM Note: Without admin, we can only toggle known Wi-Fi profiles
 REM Note: Use netconnect.bat for a more powerful adapter reset with admin
 
 setlocal enabledelayedexpansion
 set ssid=mcdonalds.foyer_nomap
 set "logdir=C:\data\sys\log"
 if not exist "%logdir%" mkdir "%logdir%"
 
 for /f %%A in ('wmic os get localdatetime ^| find "."') do set dt=%%A
 set "ts=%dt:~0,8%_%dt:~8,6%"
 set "logfile=%logdir%\wifiscan_%ts%.log"
 
 echo === Wi-Fi scan session started at %date% %time% === >> "%logfile%"
 
 REM 1) Disconnect from current SSID
 echo [%date% %time%] Disconnecting Wi-Fi...
 netsh wlan disconnect
 timeout /t 12 >nul
 
 echo === Scan A (disconnected state) at %date% %time% === >> "%logfile%"
 netsh wlan show networks mode=bssid > "%logdir%\scanA.tmp"
 type "%logdir%\scanA.tmp" >> "%logfile%"
 echo --- End of Scan A --- >> "%logfile%"
 
 REM 2) Reconnect to target SSID
 echo [%date% %time%] Reconnecting to %ssid%...
 netsh wlan connect name=%ssid%
 timeout /t 15 >nul
 
 echo === Scan B (after reconnect) at %date% %time% === >> "%logfile%"
 netsh wlan show networks mode=bssid > "%logdir%\scanB.tmp"
 type "%logdir%\scanB.tmp" >> "%logfile%"
 echo --- End of Scan B --- >> "%logfile%"
 
 REM 3) Wait longer for background scan to complete
 timeout /t 20 >nul
 echo === Scan C (delayed snapshot) at %date% %time% === >> "%logfile%"
 netsh wlan show networks mode=bssid > "%logdir%\scanC.tmp"
 type "%logdir%\scanC.tmp" >> "%logfile%"
 echo --- End of Scan C --- >> "%logfile%"
 
 REM 4) Build consolidated summary (union of SSIDs and BSSIDs with counts)
 echo === Consolidated AP Summary (union of all scans) === >> "%logfile%"
 
 REM Unique SSIDs
 echo --- Unique SSIDs --- >> "%logfile%"
 type "%logdir%\scanA.tmp" "%logdir%\scanB.tmp" "%logdir%\scanC.tmp" | findstr /R /C:"^SSID" | sort /unique > "%logdir%\ssid.tmp"
 type "%logdir%\ssid.tmp" >> "%logfile%"
 for /f %%C in ('type "%logdir%\ssid.tmp" ^| find /c /v ""') do set ssidcount=%%C
 echo Total unique SSIDs: %ssidcount% >> "%logfile%"
 
 REM Unique BSSIDs
 echo --- Unique BSSIDs --- >> "%logfile%"
 type "%logdir%\scanA.tmp" "%logdir%\scanB.tmp" "%logdir%\scanC.tmp" | findstr /R /C:"BSSID" | sort /unique > "%logdir%\bssid.tmp"
 type "%logdir%\bssid.tmp" >> "%logfile%"
 for /f %%C in ('type "%logdir%\bssid.tmp" ^| find /c /v ""') do set bssidcount=%%C
 echo Total unique BSSIDs: %bssidcount% >> "%logfile%"
 
 REM Per-scan SSID counts
 echo --- Per-scan SSID counts --- >> "%logfile%"
 for /f %%C in ('findstr /C:"SSID" "%logdir%\scanA.tmp" ^| find /c "SSID"') do set scanAcount=%%C
 for /f %%C in ('findstr /C:"SSID" "%logdir%\scanB.tmp" ^| find /c "SSID"') do set scanBcount=%%C
 for /f %%C in ('findstr /C:"SSID" "%logdir%\scanC.tmp" ^| find /c "SSID"') do set scanCcount=%%C
 echo Scan A SSIDs: %scanAcount% >> "%logfile%"
 echo Scan B SSIDs: %scanBcount% >> "%logfile%"
 echo Scan C SSIDs: %scanCcount% >> "%logfile%"
 
 REM Per-scan BSSID counts (new in v2p1)
 echo --- Per-scan BSSID counts --- >> "%logfile%"
 for /f %%C in ('findstr /C:"BSSID" "%logdir%\scanA.tmp" ^| find /c "BSSID"') do set scanAbssid=%%C
 for /f %%C in ('findstr /C:"BSSID" "%logdir%\scanB.tmp" ^| find /c "BSSID"') do set scanBbssid=%%C
 for /f %%C in ('findstr /C:"BSSID" "%logdir%\scanC.tmp" ^| find /c "BSSID"') do set scanCbssid=%%C
 echo Scan A BSSIDs: %scanAbssid% >> "%logfile%"
 echo Scan B BSSIDs: %scanBbssid% >> "%logfile%"
 echo Scan C BSSIDs: %scanCbssid% >> "%logfile%"
 
 del "%logdir%\scanA.tmp" "%logdir%\scanB.tmp" "%logdir%\scanC.tmp" "%logdir%\ssid.tmp" "%logdir%\bssid.tmp"
 
 echo === Wi-Fi scan session finished at %date% %time% === >> "%logfile%"
 echo Log written to %logfile%
 pause
 
 REM end of C:\data\sys\batch\netscan.bat 
-- 
Helping others & learning from them is what this Usenet ng is all about.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.