Closed11

[macOS 14.4以降非推奨]macOSでWifiの設定をCLIから操作する

hoshthosht

airportコマンド

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -h
Supported arguments:
 -c[<arg>] --channel=[<arg>]    Set arbitrary channel on the card
 -z        --disassociate       Disassociate from any network
 -I        --getinfo            Print current wireless status, e.g. signal info, BSSID (requires sudo), port type etc.
 -s[<arg>] --scan=[<arg>]       Perform a wireless broadcast scan.
                                   Will perform a directed scan if the optional <arg> is provided.
                                   BSSID and country code information requires sudo.
 -x        --xml                Print info as XML
 -P        --psk                Create PSK from specified pass phrase and SSID.
                                   The following additional arguments must be specified with this command:
                                  --password=<arg>  Specify a WPA password
                                  --ssid=<arg>      Specify SSID when creating a PSK
 -h        --help               Show this help
# 以下/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/にPATHが通っているものとする
hoshthosht

チャンネルを変更する
APの設定によっては反映されない

$ airport -c 100
channel: 100
hoshthosht

現在接続しているWifiの情報を表示その2
PHY Modeにプロトコルが表示される

$ system_profiler SPAirPortDataType | grep -A 6 'Current Network Information:'
hoshthosht

Wifのネットワークインターフェースを出力する

$ networksetup -setairportpower Wi-Fi off
Wi-Fi is not a Wi-Fi interface.
Turning off the only airport interface found: en0
hoshthosht

Wifiをオンにする(en0の場合)

$ networksetup -setairportpower en0 on
hoshthosht

上記を組み合わせてチャンネル接続ガチャを回す

$ airport -s
$ sudo airport -c 100 && \
    networksetup -setairportpower en0 off && \
    sleep 1 && \
    networksetup -setairportpower en0 on && \
    sleep 3 && \
    system_profiler SPAirPortDataType | grep -A 6 'Current Network Information:'
このスクラップは1ヶ月前にクローズされました