Wireshark 显示过滤器速查表
整理了最常用的显示过滤器语法、各层协议字段与捕获过滤器(BPF)的区别,抓包时开一个标签页放着就够用。
- DATE
- LEN
- 355 字
- TTL
- 1 min
- LAYER
- tools · 工具与实践
这是一份自己用的速查表,会持续更新。
捕获过滤器 vs 显示过滤器
| 捕获过滤器(Capture Filter) | 显示过滤器(Display Filter) | |
|---|---|---|
| 语法 | BPF(与 tcpdump 相同) | Wireshark 自己的语法 |
| 生效时机 | 抓包之前,不匹配的直接丢弃 | 抓包之后,只是隐藏 |
| 示例 | tcp port 443 | tcp.port == 443 |
| 适用场景 | 流量大、只关心特定流量 | 事后分析、反复筛选 |
技巧
过滤栏背景变绿色表示语法正确,红色表示语法错误——本站首页的“抓包列表”也模仿了这个设计。
运算符
| 运算符 | 含义 | 示例 |
|---|---|---|
== / eq | 等于 | ip.src == 192.0.2.1 |
!= / ne | 不等于 | tcp.port != 22 |
> < >= <= | 比较 | frame.len > 1000 |
contains | 包含 | http.host contains "example" |
matches / ~ | 正则匹配 | http.host matches "\\.cn$" |
in | 集合 | tcp.port in {80, 443, 8080} |
&& || ! | 与 / 或 / 非 | tcp && !(tcp.port == 22) |
[i:j] | 切片 | eth.src[0:3] == 00:1a:2b |
注意
!= 的历史坑
在 Wireshark 3.6 之前,ip.addr != 192.0.2.1 的含义是“源或目的有一个不等于”,几乎总为真。3.6 起 != 改为等价于 !(ip.addr == 192.0.2.1)。用老版本时请写成后者。
按协议分层的常用字段
链路层 / 网络层
eth.addr == aa:bb:cc:dd:ee:ff
arp # 所有 ARP
arp.opcode == 2 # ARP 应答
ip.addr == 192.0.2.10 # 源或目的
ip.src == 192.0.2.0/24 # 支持 CIDR
ip.ttl < 10
ip.flags.mf == 1 || ip.frag_offset > 0 # IP 分片
icmp.type == 8 # Echo Request
ipv6
传输层
tcp.port == 443
tcp.flags.syn == 1 && tcp.flags.ack == 0 # 新连接
tcp.flags.reset == 1
tcp.analysis.flags # 所有 TCP 异常(重传、乱序、零窗口……)
tcp.analysis.retransmission
tcp.analysis.zero_window
tcp.stream eq 3
tcp.len > 0 # 携带数据的报文段
udp.port == 53
应用层
dns.qry.name contains "example"
dns.flags.rcode != 0
http.request.method == "POST"
http.response.code >= 400
http.host == "example.com"
tls.handshake.type == 1 # ClientHello
tls.handshake.extensions_server_name contains "example"
quic
帧信息
frame.len > 1400
frame.time_relative > 10
frame.time_delta_displayed > 1 # 与上一个显示报文间隔超过 1 秒
frame contains "password" # 全帧搜索字节串
捕获过滤器(BPF)常用写法
host 192.0.2.10
net 192.0.2.0/24
port 53
tcp port 443
src host 192.0.2.10 and dst port 80
portrange 8000-8100
not arp and not port 22
icmp
tcp[tcpflags] & (tcp-syn) != 0
几个高频操作
- 右键字段 → Apply as Filter:最快的过滤器生成方式,不用记字段名;
- Follow → TCP Stream(
Ctrl+Alt+Shift+T):把一条流的载荷拼成对话; - Statistics → Conversations / Endpoints:一眼看出谁和谁通信最多;
- Statistics → Protocol Hierarchy:整份抓包的协议占比;
- Statistics → TCP Stream Graphs:看吞吐量、RTT、窗口变化;
- View → Coloring Rules:自定义着色规则,比如把
tcp.analysis.flags标成醒目的红色。