Look up your Mac's Wi-Fi network name (SSID) on the command line

Information can be obtained with the command airport, which is somehow deep.

$ /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

Pull out only where you want it

Shell is like this

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

Python is like this

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!!!

For example, I made a command line tool that I can use at home and at work, but I have to set a proxy at work.

Recommended Posts

Look up your Mac's Wi-Fi network name (SSID) on the command line
Keep getting RSS on the command line
You search commandlinefu on the command line
Quickly display the QR code on the command line
Arduino development on the command line: vim + platformio
Syntax highlighting on the command line using Pygments
Convert XLSX to CSV on the command line
Operate Route53 on the command line using AWS-CLI.
Think about the selective interface on the command line
Speed up the netstat command
A command to easily check the speed of the network on the console
Python standard module that can be used on the command line