1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WiFi調査bat

Posted at

背景

「WiFi空いてる?」
「いやWiFi飛んでるな~」
「ログに残してレポートにしたいな」

予備知識

Windows10のコマンドプロンプトで
WiFiに接続しない状態で以下のコマンドを叩くと

netsh wlan show networks mode=bssid

以下のような結果が取れる

SSID 1 : nazonowifi
    Network type            : Infrastructure
    Authentication          : Open
    Encryption              : None 
    BSSID 1                 : 00:00:00:00:00:00
         Signal             : 72%  
         Radio type         : 802.11n
         Channel            : 6 
         Basic rates (Mbps) : 1 2 5.5 11
         Other rates (Mbps) : 6 9 12 18 24 36 48 54

これを分析しにくいからパースしてCSV化する。

出来たもの

@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

for /f "tokens=1-5 delims=/: " %%A in ("%date% %time%") do (
    set year=%%A
    set month=%%B
    set day=%%C
    set hour=%%D
    set minute=%%E
)
set datetime=%year%%month%%day%_%hour%%minute%

set logname=wifi_%datetime%.log
set csvname=wifi_%datetime%.csv

netsh wlan disconnect
netsh wlan show networks mode=bssid > !logname!

if %errorlevel% neq 0 (
    echo netshコマンドの実行に失敗
    exit /b
)

echo SSID,Authentication,Encryption,BSSID,Signal,RadioType,Channel,BasicRates,OtherRates > !csvname!

for /f "tokens=1,* delims=:" %%A in (!logname!) do (
    set line=%%A
    set value=%%B
    if not "!line:BSSID=!" == "!line!" (
        set bssid=!value:~1!
    )else if not "!line:SSID=!" == "!line!" (    
        set ssid=!value: =!
    )else if not "!line:Authentication=!" == "!line!" (    
        set auth=!value: =!
    )else if not "!line:Encryption=!" == "!line!" (    
        set encryption=!value: =!
    )else if not "!line:Signal=!" == "!line!" (    
        set signal=!value: =!
    )else if not "!line:Radio type=!" == "!line!" (    
        set radiotype=!value:~1!
    )else if not "!line:Channel=!" == "!line!" (    
        set channel=!value: =!
    )else if not "!line:Basic rates=!" == "!line!" (    
        set basicrates=!value:~1!
    )else if not "!line:Other rates=!" == "!line!" (    
        set otherrates=!value:~1!
        echo !ssid!,!auth!,!encryption!,!bssid!,!signal!,!radiotype!,!channel!,!basicrates!,!otherrates!>> !csvname!
    )
)

あとがき

連続で複数回実行するのは別のbatでやってね。
ログはbatと同じフォルダに吐くから別のbatで退避させてね。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?