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

tshark capture only dns or http traffic with specific ip adress and write to file

您好,我想从特定的 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 instead. Capture filters use a 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)"