Scripting the sniffer built into Wireless Diagnostics

I'm interested in using the built-in wireless sniffer (accessible from Wireless Diagnostics by pressing Cmd-Opt-6) as a part of a script. Is there a way to control it via scripting, maybe AppleScript?

I need to:

  • start the sniffer
  • change the channel and bandwidth settings
  • output to a file (as usual)

Can the UI be scripted with input events? Does Wireless Diagnostics offer any Apple events?


Solution 1:

Following this answer, I'd suggest starting by symlinking the airport tool, which is the backend behind the Wireless Diagnostic tool:

sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

and using it to sniff e.g. on channel 1 on your connection en1 (see ifconfig to figure out which network interface is the wireless one) via:

sudo airport en1 sniff 1

which will create a uniquely named .cap file in /tmp/. Use ctrl+c to end the sniffing. (Note that /tmp/ will be cleaned on reboot!)

Note that you can also use tcpdump directly for sniffing, without disassociating from wireless networks by:

sudo /usr/sbin/tcpdump -nei en1 -s 0 -w /tmp/scan.pcap