Created
September 12, 2019 02:42
-
-
Save recuraki/d938153b070ba9abc85f5a0e170c8295 to your computer and use it in GitHub Desktop.
Windowsで今つながっているBSSIDからAP名を引くスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apのcsvファイルをここに張る | |
$apcsv=@" | |
6c:e4:da:ff:ff:ff,ap-ateam001 | |
"@ | |
################################## | |
# AP Listの用意 | |
$aptable=@{} | |
# AP CSVからAP Listにインポートする | |
foreach($apstr in $apcsv){ | |
$apbssid=$apstr.ToString().split(",")[0].trim() | |
$apname=$apstr.ToString().split(",")[1].trim() | |
$aptable.add($apbssid, $apname) | |
} | |
################################## | |
# $orig_code=(chcp).split(":")[1].trim() | |
# 現在のwifi情報を取得 | |
chcp 65001 | out-null ; $result=netsh wlan show interfaces | |
# 注意: Indexがハードコードされている | |
# wifi情報をパースして必要な情報を得る | |
$wifistate=$result[7].split(":")[1].trim() | |
$bssid=$result[9].ToString() | |
$bssid=$bssid -split ':',2 | |
$bssid=$bssid[1].trim() | |
if($wifistate -ne "connected"){ | |
# WiFiに接続していない場合のエラー | |
echo "ERROR: WiFi is not connected" | |
} | |
else{ | |
# WiFiに接続している場合は現在接続しているBSSIDの表示 | |
echo "BSSID= $bssid" | |
if ($aptable.ContainsKey($bssid)){ | |
# APListに乗っている = KNOWNなIDの場合 | |
echo "APNAME:" $aptable[$bssid] | |
} | |
else{ | |
# APListに乗っていない = 別の無線NWや未知のAPである場合 | |
echo "ERROR: UNKNOWN AP" | |
} | |
} | |
#chcp $orig_code | out-null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行例:
PS C:\Users\kanai\Desktop> wifi.ps1