首页 > 解决方案 > macos 中“任何”伪设备的模拟

问题描述

是否有可能通过 tcpdump 从 MacOS 中的所有设备捕获数据包?在 Linux 中,我会使用“sudo tcpdump -i any”。在我的 MacOS 中,当我执行“sudo tcpdump -D”时,我看不到“任何”伪设备。

标签: macoscapturetcpdumpany

解决方案


根据@ChristopherMaynard:
tcpdump 文档指定any为在 linux 上工作:On Linux systems with 2.2 or later kernels, an interface argument of ``any'' can be used to capture packets from all interfaces.但是,它实际上并不是特定于操作系统的。


tcpdumpany在我的测试中接受了 macos 上的接口,所以在回答你的问题时,any在 linux 上的模拟是any在 macos 上:

bash-5.0 $ sudo tcpdump -i any
tcpdump: data link type PKTAP
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
09:43:57.789302 IP6 dsldevice7.attlocal.net.domain > 2600:1700:a700:7340:6dad:2758:c536:f29f.56483: 4283 1/0/0 SOA (85)
09:43:57.789324 IP6 2600:1700:a700:7341:6dad:2759:c536:f29f > dsldevice7.attlocal.net: ICMP6, destination unreachable, unreachable port, 2600:1700:a700:7340:6ded:2759:c536:f29f udp port 56423, length 141
...

tcpdump 在 macos 和 linux 上应该有相同的选项(manpage),除了下面详述的那些。如果你有旧版本的 tcpdump(我的版本是 4.9.3/Apple 版本 83.200.3),你可以用brew install tcpdump.

Macos/Linux Tcpdump 差异

如有疑问,您仍应查看联机帮助页,但这是对差异的总结:

Linux

  • -Q direction:选择发送/接收方向(in/out/inout)

苹果系统

  • -k: 控制数据包元数据的显示
  • -Q:指定基于数据包元数据的过滤器表达式
  • -P: 保存到 pcapng

注意:与 Linux 或 *BSD 不同,Macos不支持 -Q 方向


推荐阅读