Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get wireless SSID through shell script on Mac OS X

Tags:

shell

macos

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

like image 402
Mark Szymanski Avatar asked Dec 19 '10 00:12

Mark Szymanski


People also ask

How do I find my Wi-Fi SSID on Mac?

Mac OS. Select the Wi-Fi icon in the menu bar. Within the list of networks, look for the network name listed with a check mark. This is your network's SSID.

What is my Wi-Fi SSID?

On Android:From the homepage or app list, select Settings. Select Wi-Fi. In the list of networks, look for the network name listed next to Connected. This is the SSID.


3 Answers

The command

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

will give you details about your current wireless network connection.

To get specifically the SSID, use this command:

/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F: '/ SSID/{print $2}'

To retrieve SSID names that might have colons as well as spaces:

/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I  | awk -F' SSID: '  '/ SSID: / {print $2}'
like image 189
Chetan Avatar answered Oct 19 '22 08:10

Chetan


Where isn't there a wheel in need of re-inventing?

networksetup -getairportnetwork en1 | cut -c 25-

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

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

In case the device is named something other than en1, one needs to first get the correct device name, than the corresponding SSID:

networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}' | xargs networksetup -getairportnetwork
like image 39
Sacrilicious Avatar answered Oct 19 '22 08:10

Sacrilicious


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

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

Essentially, this takes the output of system_profiler SPAirPortDataType, and prints the line after "Current Network Information:" trimming leading whitespace and the trailing colon (since SSIDs can contain :s).

like image 7
Johnsyweb Avatar answered Oct 19 '22 06:10

Johnsyweb