tshark - 按网络服务名称过滤

tshark - filtering by webservice's name

我正在尝试使用 tshark 记录发送到名为 myservice.

的 WebService 的每个请求

当我使用下面的命令时,我可以在输出文件中看到在端口 8280 (Tomcat) 上发送的每个请求:

tshark -n -i eth1 port 8280 -w output.pcap

考虑到我在那个 Tomcat 实例中有很多 WebServices,我想按服务名称过滤,类似这样的东西:

tshark -n -i eth1 port 8280 -w output.pcap -R 'http.request.uri contains "myservice"'

根据 man,看起来我应该使用 -f(捕获过滤器)而不是 -R(显示过滤器)因为你不能使用 -R-w :

tshark: Read filters aren't supported when capturing and saving the captured packets.

我查看了 documentation about capture filters,但我看不到这样做的方法。我也试过 tcpdump 没有成功。

你可以使用 ngrep 来完成这个

sudo ngrep -O output.pcap -i -d eth0 'myservice'

虽然您可能会得到一些误报,具体取决于 'myservice' 是否在不适合您的应用程序的无关数据包上找到。为避免这种情况,您可能希望应用 bpf 过滤器以仅对定向到您的 service/app

的流量进行 grep
sudo ngrep -O output.pcap -i -d eth0 'myservice' 'tcp dst port 8280'