Get wireless SSID through shell script in Mac OS X

Is there a way to get the SSID of the current wireless network through a shell script in Mac OS X?

+58
shell macos
Dec 19 '10 at 0:29
source share
3 answers

Team

/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I 

will tell you about your current wireless connection.

To get the specific SSID, use this command:

 /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F: '/ SSID/{print $2}' 
+104
Dec 19 '10 at 0:32
source share

Where there is no wheel to reinvent?

 networksetup -getairportnetwork en1 | cut -c 25- 

- this is what you would use on 10.6, 10.7 changed the name "Hardware Port" from "Airport" to "Wi-Fi", and therefore you would cut one letter less,

 aru$ networksetup -getairportnetwork en1 | cut -c 24- Yorimichi 

If the device has a name other than en1 , first you need to get the correct device name, and not the corresponding SSID:

 networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork 
+38
Dec 17 2018-11-11T00:
source share

In OS X, the following has been tested and prints the SSID without any hard-coded column widths:

 system_profiler SPAirPortDataType | awk -F':' '/Current Network Information:/ { getline sub(/^ */, "") sub(/:$/, "") print }' 

Essentially, this outputs the result of the system_profiler SPAirPortDataType and prints a line after the " Current Network Information: " trimming leading spaces and a back colon (since the SSIDs may contain : s).

+6
Dec 19 2018-10-12T00:
source share



All Articles