普段所属しているサークルの部室で作業をしていると,時々サークルのWifiから大学が提供するWifi(遅い)に勝手に切り替わってしまうことがある.
Windows10の標準ではタスクバーの「インターネットアクセス」のアイコンにカーソルを合わせなければ,現在接続中のSSIDを表示できない.
これが不便に感じたので,PowerShellでLANの情報を取得するスクリプトを作成した.
作成したスクリプト
$code=(chcp).split(":")[1].trim()
chcp 65001 | out-null
$STATE=7
$SSID=8
$SIGNAL=18
$result=netsh wlan show interfaces
if ( $result[$STATE].split(":")[1].trim() -eq "connected"){
echo ($result[$SSID].split(":")[1].trim()+":"+$result[$SIGNAL].split(":")[1].trim())
}else{
echo "LAN disconnected"
}
chcp $code | out-null
説明とか
$result=netsh wlan show interfaces
で現在接続中のLANの情報が取得できる
実行例1(接続されている場合)
>$result=netsh wlan show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : ***
GUID : ***
Physical address : ***
State : connected
SSID : ***
BSSID : ***
Network type : Infrastructure
Radio type : 802.11n
Authentication : WPA2-Personal
Cipher : CCMP
Connection mode : Profile
Channel : ***
Receive rate (Mbps) : 43.3
Transmit rate (Mbps) : 43.3
Signal : 99%
Profile : ***
Hosted network status : Not available
実行例2(接続されていない場合)
>$result=netsh wlan show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : ***
GUID : ***
Physical address : ***
State : disconnected
Radio status : Hardware On
Software On
Hosted network status : Not available
Stateがdisconnectなら接続されていない
echo ($result[$SSID].split(":")[1].trim()+":"+$result[$SIGNAL].split(":")[1].trim())
で必要な情報(この場合はSSIDと電波強度)を表示する.必要に応じて適当に変えればよいと思う