Get wireless SSID through shell script on Mac OS X

后端 未结 3 1111
無奈伤痛
無奈伤痛 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:37

    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).

提交回复
热议问题