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:
> Looking it up, this "supposedly" triggers a scan on all Wi-Fi interfaces:
>  $wifi = New-Object -ComObject Wlanapi.WlanClient
>  $wifi.Interfaces | ForEach-Object { $_.Scan() }

That didn't work because the command isn't exposed on my Windows 10 system.

This "concept" is probably the best we can do without going to 3rd-party 
tools, where just retriggering doesn't work because it's the same cache.
 @echo off
 :: C:\data\sys\batch\triggerwifi.bat
 :: v1p0 20251215
 ::  repeatedly trigger scans and then dump the results.

 setlocal
 set SCANS=5

 for /L %%i in (1,1,%SCANS%) do (
    echo ==== Scan %%i ====
    netsh wlan show networks mode=bssid
    timeout /t 3 >nul
 )

 endlocal
 pause

The "best" so far that I've found that seems to get a "fuller" output is 
this script which disassociates & reassociates & then scans thereafter.

It expressly runs a disconnect and scan, a reconnect and scan, and a 
delayed snapshot and scan because Windows often caches results differently
depending on association state.

But sometimes it leaves the WI-FI adapter in the off state, so I need to
add some kind of protection code to make sure the adapter is online.

If we're willing to run with elevated privileges, we could force a full
adapter reset before scanning, but even then we could miss some APs.
  netsh interface set interface name="Wi-Fi" admin=disabled
  timeout /t 5 >nul
  netsh interface set interface name="Wi-Fi" admin=enabled

 @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 Designed to NOT require admin 
 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=exxon.store_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
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.