Apple used to provide a binary called airport at the following location -
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport
This was able to scan for and produce a list of available SSIDs which would look like the following.
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
vodafone20645C -89 6 Y -- RSN(PSK/AES/AES)
vodafone20645C -89 60 Y -- RSN(PSK/AES/AES)
ALCL-HGU -88 1 Y -- RSN(PSK/AES/AES)
SKY69QVQ -84 11 Y -- RSN(PSK/AES/AES)
Unfortunately as of macOS Sonoma 14.4 this tool is now deprecated and if executed only displays the following error message.
WARNING: The airport command line tool is deprecated and will be removed in a future release. For diagnosing Wi-Fi related issues, use the Wireless Diagnostics app or wdutil command line tool.
It goes without saying that neither of the referred to tools is a suitable substitute.
I have found a very helpful article on stackoverflow -
How to enable location services for CoreWLAN pyobjc wrapper to get bssid?
Using this as a starting point and by adding the following to it -
for i in networks:
if i.ssid() is None:
continue
print({'SSID_STR': i.ssid(), 'BSSID': i.bssid(), 'RSSI': i.rssiValue(), 'CHANNEL': i.channel()})
I have already been able to get a result like the following
{'SSID_STR': 'vodafone20645C', 'BSSID': None, 'RSSI': -89, 'CHANNEL': 6}
{'SSID_STR': 'vodafone20645C', 'BSSID': None, 'RSSI': -89, 'CHANNEL': 60}
{'SSID_STR': 'ALCL-HGU', 'BSSID': None, 'RSSI': -88, 'CHANNEL': 1}
{'SSID_STR': 'SKY69QVQ', 'BSSID': None, 'RSSI': -84, 'CHANNEL': 11}
I am however whilst an experienced shell script author very much a novice for Python and was hoping for help in getting this Python output to look exactly like the output from the Apple airport command. The format of the output from the airport command is used by many other existing tools. This would then allow the intended python script to be used as a replacement for the airport tool.
This will involve - if possible adding additional fields e.g. relating to the security settings, and in particular formatting the output to be the same layout as that formerly produced by the airport tool. You will note the righthand alignment of the SSID values in the airport output.
I could I feel already take the above and feed it back to a shell script and use awk, sed, etc. to extract the fields for my own requirement, however in the interest of generating a solution that would be directly usable by anyone (like me) who has previously relied on the airport command, it would be more useful to produce an identical format output.