2
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?

More than 3 years have passed since last update.

WiFiの通信量ページから判断して接続先SSID切替える

Last updated at Posted at 2021-03-23

Nuro光の工事が3か月たっても終わらないので
諦めてWiFiとキャリアのテザリング回線を使い倒す環境作っていく。

memo:
WiFiはキャッシュされた情報を使いまわすため指定プロファイルで接続できない事が多い。
対策として、つなぎ直す前にインターフェースを一旦無効化しwlanscanを発生させることにした。

環境

Windows10 ノートPC。
事前にWiFi接続して使用するSSIDのプロファイルが保存されている必要があります。

WiFiの回線 SSID "GroupWiFi_xi0aouh"
1日最大10GB。1バイトでも超えると容赦なく128kbpsに切り替える。
回線状態は ttps://192.168.65.1/status_info_iframe.html に表示されていることを確認ずみ。

テザリング回線 SSID "なぜここがわかった"
mineoの500kbps使い放題。Youtubeも最低画質にすれば見れる。

実装

タスクスケジューラで10分ごとに次のPowershellを実行します

# netshで接続中のSSIDを取得
$text =(netsh wlan show interface | Select-String "プロファイル  ")
# 3/26 検索文字に半角スペース足した

if($text.ToString().Contains("GroupWiFi_xi0aouh")){
    #HTMLを取得
    $html=(Invoke-WebRequest http://192.168.65.1/status_info_iframe.html)

    #現在の使用量が書かれているクラスの値を取得
    $bytes=($html.ParsedHtml.getElementsByClassName("ui-em-20")|Select-Object innerText)

    #10GB超えてたらテザリング回線に切り替え
    if($bytes.innerText.Contains("10.")){
        #WLANキャッシュ対策
        netsh interface set interface name=Wi-Fi admin=disabled
        netsh interface set interface name=Wi-Fi admin=enabled
        Start-Sleep -s 2
        netsh wlan connect name="なぜここがわかった"
    }
}

はやく光の工事きてくれーーー!!

2
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
2
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?