使用来自 OS X 的脚本嗅探网络流量

Sniffing network traffic using a script from OS X

我来自 linux 背景,最近获得了 mac。在 linux 中,我有很多用 python 编写的脚本,用于执行特定的数据包嗅探和捕获。专用取消身份验证数据包捕获或其他无线探测。为此,我会将我的无线适配器设置为监控模式,然后使用 scapy 或命令

    sniff = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)

遗憾的是,我发现 OS X 不支持这种嗅探方式。我知道 airport 命令和苹果提供的隐藏无线嗅探器,但它们的使用非常有限。我正在寻找可以与我的脚本一起使用的东西。

我想知道是否有人想出解决此问题的方法。是否可以将此功能添加到 python 和 ruby 等语言?

如果没有,是否可以在 swift 中编写具有相同功能的数据包嗅探器?

Sadly, I have discovered that this style of sniffing is not supported by OS X.

是的,它是 BSD 风格的 OS,所以,它不是 Linux 风格的 PF_PACKET 套接字,而是 BSD 风格的 BPF devices.

I was wondering if anyone has figured a way around this issue

是的。它被称为"use libpcap, which will use PF_PACKET sockets on Linux and BPF devices on OSes that have BPF devices and other mechanisms on OSes that have other packet capture mechanisms, rather than directly using the native OS mechanism"。

Is it possible to add this feature to languages like python

因为 "this feature" 表示 "using libpcap"、yes, it is. You could also use Scapy,它提供比 "get me the raw bytes of captured packets" API 更高级的 API。

and ruby?

Yes.