LoginSignup
10
8

More than 5 years have passed since last update.

MacのWi-Fiネットワーク名(SSID)をコマンドラインで調べる

Posted at

なにやら深いところにいるairportというコマンドで情報が取得できる

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
     agrCtlRSSI: xxx
     agrExtRSSI: xxx
    agrCtlNoise: xxx
    agrExtNoise: xxx
          state: xxx
        op mode: xxx
     lastTxRate: xxx
        maxRate: xxx
lastAssocStatus: xxx
    802.11 auth: xxx
      link auth: xxx
          BSSID: xxx
           SSID: HERE!!!
            MCS: xxx
        channel: xxx

てきとーに欲しいところだけ引っこ抜く

Shellだとこんな

$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep " SSID" | tr -d " " | cut -c6-
HERE!!!

Pythonだとこんな

import commands

airport = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"

print [line for line in commands.getoutput(airport).split('\n') if " SSID" in line][0].split(':')[1].strip()

# HERE!!!

例えば家でも会社でも使うコマンドラインツールを作ったけど、会社ではプロキシ設定しないといけないとか、そんな時用。

10
8
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
10
8