Get wlan AP info

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 732
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Get wlan AP info

Post by Grovkillen » Wed Apr 01, 2020 11:50 am

This script will list all APs and their info. Please remember that the scan isn't done by the netsh app itself so if you do this after the computer has been running for a while it will only return the AP that the computer is connected to. If you want to trigger a new scan you need to disable and then enable the wlan (I have that commented out in the script below) but that require the script to have admin rights. But if you do this right after the computer has booted you will get a full scan list without admin rights.

Code: Select all

Let>RP_WAIT=1
MidStr>%SCRIPT_DIR%,0,1,VOLUME_LETTER
IfFileExists>%SCRIPT_DIR%\dump.txt
  DeleteFile>%SCRIPT_DIR%\dump.txt
Endif>
IfFileExists>%SCRIPT_DIR%\wlan_scan.txt
  DeleteFile>%SCRIPT_DIR%\wlan_scan.txt
Endif>
  //Script require admin rights if you want to force a new scan
  //Let>TOGGLE_WLAN=netsh interface set interface name=%WLAN_NAME% admin
  //Let>COMMAND_LINE_STRING=cmd /c %VOLUME_LETTER%: & cd "%SCRIPT_DIR%" & %TOGGLE_WLAN%=disabled & %TOGGLE_WLAN%=enabled & netsh wlan show networks mode=bssid > "wlan_scan.txt"
Let>COMMAND_LINE_STRING=cmd /c %VOLUME_LETTER%: & cd "%SCRIPT_DIR%" & netsh wlan show networks mode=bssid > "wlan_scan.txt"
RunProgram>COMMAND_LINE_STRING
ReadFile>%SCRIPT_DIR%\wlan_scan.txt,TEMP_WLAN_SCAN
Let>REGEX_PATTERN=SSID \d* : 
RegEx>REGEX_PATTERN,TEMP_WLAN_SCAN,0,,,1,||,TEMP_WLAN_SCAN

Separate>TEMP_WLAN_SCAN,||,TEMP_SSID_WITH_BSSID
Let>SSID=
Let>SSID_NUM=0
Let>LIST=
Let>k=0
Repeat>k
  Let>k=k+1
  Let>TEMP_NETWORK=TEMP_SSID_WITH_BSSID_%k%
  MidStr>TEMP_NETWORK,0,1,TEST
  If>TEST={" "}
    //skip this one
  Else>
    Let>SSID_NUM=SSID_NUM+1
    Separate>TEMP_NETWORK,%CRLF%,TEMP_NETWORK_SSID_INFO
    Trim>TEMP_NETWORK_SSID_INFO_1,TEMP_SSID
    Let>WLAN_SSID_%SSID_NUM%=%TEMP_SSID%
    WriteLn>%SCRIPT_DIR%\dump.txt,,%CRLF%### %SSID_NUM% ###
    WriteLn>%SCRIPT_DIR%\dump.txt,,SSID:%TEMP_SSID%
    ConCat>SSID,TEMP_SSID
    IfNot>k=TEMP_SSID_WITH_BSSID_count
      ConCat>SSID,%CRLF%
    Endif>
    RegEx>    BSSID ,TEMP_NETWORK,0,,,1,||,TEMP_ROW_BSSID_K
    Separate>TEMP_ROW_BSSID_K,||,TEMP_ROW_BSSID_INFO_K
    //We skip the first match since we're only wanting the BSSIDs
    Let>p=1
    Repeat>p
      Let>p=p+1
      Let>WLAN_SSID_%SSID_NUM%_BSSID_count=p-1
      Let>TEMP_ROW_BSSID_P=TEMP_ROW_BSSID_INFO_K_%p%
      Separate>TEMP_ROW_BSSID_P,%CRLF%,TEMP_ROW_X
      Let>x=0
      Repeat>x
        Let>x=x+1
        Let>TEMP_X=TEMP_ROW_X_%x%
        Length>TEMP_X,TEST_ROW
        If>TEST_ROW>0
          Separate>TEMP_X, : ,TEMP_X_SEP
          Trim>TEMP_X_SEP_1,TEMP_ROW_VAR
          RegEx> ,TEMP_ROW_VAR,0,,,1,_,TEMP_ROW_VAR
          Trim>TEMP_X_SEP_2,TEMP_ROW_VAL
          If>x=1
            Let>WLAN_SSID_%SSID_NUM%_BSSID_%p%_MAC=TEMP_ROW_VAL
            Let>TEMP_P=WLAN_SSID_%SSID_NUM%_BSSID_count
            WriteLn>%SCRIPT_DIR%\dump.txt,,### BSSID %SSID_NUM%:%TEMP_P% ###
            WriteLn>%SCRIPT_DIR%\dump.txt,,%TAB%MAC:%TEMP_ROW_VAL%
          Else>
            Let>WLAN_SSID_%SSID_NUM%_BSSID_%p%_%TEMP_ROW_VAR%=TEMP_ROW_VAL
            WriteLn>%SCRIPT_DIR%\dump.txt,,%TAB%%TEMP_ROW_VAR%:%TEMP_ROW_VAL%
          Endif>
        Endif>
      Until>x=TEMP_ROW_X_count
    Until>p=TEMP_ROW_BSSID_INFO_K_count
  Endif>
Until>k=TEMP_SSID_WITH_BSSID_count


ExecuteFile>%SCRIPT_DIR%\dump.txt
Let>ME=%Script%

Running: 15.0.19b
version history

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts