Get wireless SSID through shell script on Mac OS X

后端 未结 3 1102
無奈伤痛
無奈伤痛 2020-12-07 12:02

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

3条回答
  •  醉梦人生
    2020-12-07 12:41

    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
    

提交回复
热议问题