在命令行中使用 wireshark/tshark 忽略 ssh 连接

在命令行中使用 wireshark/tshark 忽略 ssh 连接

我正在尝试通过查看数据包来调试一些问题,并且我想避免将所有 SSH 流量发送到服务器。有没有办法忽略?

我尝试做类似的事情tshark -f "port !22"但它在命令之后停止了监听。

[root@vpn ~]# tshark -f "port !22"
tshark -f "port ls"
Running as user "root" and group "root". This could be dangerous.
Capturing on venet0
tshark: arptype 65535 not supported by libpcap - falling back to cooked socket.

tshark: Invalid capture filter: "port ls"!

That string isn't a valid capture filter (unknown port 'ls').
See the User's Guide for a description of the capture filter syntax.
0 packets captured
[root@vpn ~]#

答案1

tshark 和 tcpdump 都使用该pcap库,因此捕获过滤器使用pcap-filter 语法。正如@tristan 所说,您想要的过滤器是"not port 22"。您可以将其作为选项的带引号的字符串参数输入-f,也可以将其作为命令的不带引号的参数输入。以下命令是等效的:

# tshark -f "not port 22"
# tshark -- not port 22

tshark 抱怨上述命令的原因是,你的 shell(可能是 Bash)将“!22”扩展为命令历史记录中的第 22 个命令,在本例中为“ls”。Bash 文档有更多有关历史扩展的信息。

答案2

我目前无法访问 tshark 安装,但假设它与 tcpdump 相同:

sudo tcpdump not port 22

因此,有可能:

tshark not port 22 

相关内容