tshark仅捕获具有特定IP地址的dns或http流量,并写入文件

问题描述

您好,我想从特定的IP地址dns或http或http2通信中捕获并将其保存到文件中。 我尝试过:

tshark -i xxx -w capture-output.pcap -T fields -e ip.src -Y "ip.src == 192.168.178.xxx and (dns or http or http2)"

我收到此错误: tshark:捕获和保存捕获的数据包时不支持显示过滤器。

有人可以帮我吗?

解决方法

该错误会为您提供所需的尽可能多的信息-保存数据包捕获时无法使用显示过滤器。您在这里有两个选择:

选项1:保存捕获并随后使用显示过滤器

这看起来像

# Write the initial file with incoming packets
$ tshark -i xxx -w capture-output.pcap
# Filter out the traffic we don't want
$ tshark -r capture-output.pcap -w filtered-output.pcap \
    -T fields -e ip.src -Y "ip.src == 192.168.178.xxx and (dns or http or http2)"

选项2:使用捕获过滤器

请改用capture filter。捕获过滤器使用的special syntax与显示过滤器不同。

要为显示过滤器使用的等效捕获过滤器是

$ tshark -w filtered.pcap -f "src net 192.168.178.0/24 and (udp port 53 or tcp port 80 or tcp port 443)"