# Wireshark

**Wireshark** 是一款免费、图形化的网络协议分析器，可从网络接口捕获实时数据包，或读取已保存的捕获文件，并显示每个数据包的详细协议信息。它可运行于 UNIX 和 Windows，能打开 tcpdump 及其他工具生成的文件，对数据包进行过滤和着色，并据此生成统计数据<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。一篇经同行评审的综述称其为世界上最流行的网络协议分析器<sup>[2](https://dl.acm.org/doi/10.1016/j.comcom.2021.11.009)</sup>。它是一种被动测量工具：不是入侵检测系统，不会对异常网络行为发出警告，也不操纵网络或发送数据包——唯一例外是可禁用的可选名称解析<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 是什么 | 图形化网络协议分析器；原生捕获格式为 pcapng 和 pcap，后者与 tcpdump 共用<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup> |
| 捕获引擎 | Wireshark 本身不能捕获流量；它调用 dumpcap 辅助程序，后者在 UNIX 上使用 libpcap，在 Windows 上使用 Npcap<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup> |
| 两种过滤语言 | 捕获过滤器使用 pcap/BPF 语法（如 `tcp port 80`），在捕获时应用；显示过滤器使用 Wireshark 语法（如 `tcp.port == 80`），作用于视图<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup><sup> • </sup><sup>[5](https://gitlab.com/wireshark/wireshark/-/wikis/DisplayFilters)</sup> |
| 性能上限 | 在 10 Gbit 线速下，最小尺寸以太网帧每 67 纳秒到达一个（1.25 GB/s，每秒 1488 万个数据包）；Wireshark 受限于 CPU，通常无法实时处理<sup>[6](https://sharkfest.wireshark.org/retrospective/sfeu/presentations16eu/02.pdf)</sup> |
| 丢包数据 | 配置不足的捕获工具可能丢失 5% 至 90% 以上的接收数据包；丢包率低于 3% 大概可以接受，超过 5% 则需要调优<sup>[7](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)</sup> |
| TLS 解密 | 包含每会话密钥的密钥日志文件即使在使用 Diffie-Hellman 密钥交换时也能解密 TLS；RSA 私钥仅在有限情况下有效<sup>[8](https://wiki.wireshark.org/TLS)</sup> |
| Windows 捕获库 | Wireshark 4.6.0 放弃了对 WinPcap 的支持（最终版本为 4.1.3，2013 年）；Windows 用户必须使用 Npcap<sup>[9](https://lists.wireshark.org/archives/wireshark-users/202605/msg00005.html)</sup> |
| 内存 | 处理中小型捕获文件建议至少 500 MB 可用内存；更大文件需要更多内存，内存不足时 Wireshark 可能崩溃<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup> |

## 捕获的工作原理

Wireshark 将捕获工作委托给一个独立进程。程序本身是图形化的被动分析工具，不能捕获流量；它调用 **dumpcap** 来执行实际捕获<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup>。dumpcap 又依赖链路层捕获库：在类 UNIX 系统上是 libpcap，它在此充当行业标准的捕获接口；在 Windows 上是 Npcap，即 Nmap 项目的嗅探库，自 Wireshark 第 3 版起取代 WinPcap，通过 NDIS 6 轻量级筛选器 API 支持 [Windows 7](https://www.edgepedia.org/zh/windows-7) 及更高版本<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup>。libpcap 之所以存在，正是因为几乎所有系统厂商都提供不同的[数据包捕获](https://www.edgepedia.org/zh/packet-capture)接口；该库提供一个与系统无关的 API，使工具易于移植<sup>[10](https://github.com/the-tcpdump-group/libpcap)</sup>。Npcap 可限制为仅管理员可嗅探，提供环回捕获，并能以 WinPcap 兼容模式安装；配套的 USBPcap 将捕获扩展到 USB 流量<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup>。Wireshark 可从多种介质类型捕获，包括以太网、无线局域网、蓝牙和 USB，具体受硬件和操作系统限制<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。

**在哪里捕获很重要。** 在以太网上，要看到并非发往本机适配器的流量，通常需要在该适配器上启用[混杂模式](https://www.edgepedia.org/zh/promiscuous-mode)<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup>。在交换网络中，捕获点决定了到达工具的是什么。SPAN 端口（交换机端口镜像）在负载下可能丢包，因为交换机可能优先处理实时流量而首先丢弃镜像数据包；它们通常不复制畸形或错误数据包，且大多数交换机仅支持一两个活动 SPAN 会话。硬件 TAP 可复制数据包，包括畸形帧和物理层错误；无源光纤 TAP 据称不产生性能影响，而在负载下避免丢包取决于捕获配置，因此推荐用于可经得起取证检验的数据包记录<sup>[11](https://www.networkcritical.com/blogs/a-complete-guide-to-network-packet-capture)</sup>。更广泛地说，捕获方法包括选择分接点、交换和路由网络上的捕获、无线捕获、两处同时捕获以及远程捕获<sup>[12](https://elhacker.info/manuales/Redes/wireshark-network-analysis-second-edition.pdf)</sup>。

对于长期捕获，Wireshark 可将数据包保存到多个文件，并可选在固定数量的文件间轮转，即**环形缓冲区**<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。

## 过滤器、解析与用户界面

Wireshark 有两种截然不同的过滤语言。**捕获过滤器**遵循 pcap 库的 BPF 规则，在捕获时应用。**显示过滤器**使用 Wireshark 自有语法，作用于显示内容，可随时更改，还驱动着色规则<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup><sup> • </sup><sup>[5](https://gitlab.com/wireshark/wireshark/-/wikis/DisplayFilters)</sup><sup> • </sup><sup>[7](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)</sup>。效率差异是真实存在的：捕获过滤器比读取过滤器高效得多，如果在实时捕获时指定了读取（显示）过滤器，TShark 可能难以跟上繁忙的网络<sup>[13](https://linux.die.net/man/1/tshark)</sup>。

界面有三个联动的窗格。数据包列表为每个数据包显示一行摘要；数据包详情窗格以可展开的树形显示所选数据包的协议和字段；数据包字节窗格显示规范的十六进制转储，每行包含偏移量、十六个十六进制字节和十六个 ASCII 字节，不可打印字符以句点表示<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。解析器、插件和显示过滤器在核心引擎中应用于传入流量，各窗格联动以便导航<sup>[4](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)</sup>。有一条阅读惯例很重要：高层协议会覆盖低层的列信息，因此列通常显示尽可能高的层；在以太网帧封装 IP、IP 再封装 TCP 的数据包中，TCP 会覆盖 IP 信息<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。

Wireshark 可重组 TCP 会话中的所有数据包，并显示该会话的 ASCII、EBCDIC 或十六进制数据，从而将请求和响应作为连续流而非独立分段来阅读<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup>。

## 解密 TLS 流量

Wireshark 支持三种 TLS 解密方法：每会话密钥的密钥日志文件、RSA 私钥和预共享密钥（PSK）<sup>[8](https://wiki.wireshark.org/TLS)</sup>。包含相关每会话密钥的密钥日志文件即使在使用 Diffie-Hellman 密钥交换时也能实现解密，而 RSA 私钥解密仅在有限情况下有效<sup>[8](https://wiki.wireshark.org/TLS)</sup>。Firefox、Chrome 和 curl 等应用程序可配置为导出密钥日志（SSLKEYLOGFILE 机制），Wireshark 在“编辑→首选项→协议→TLS”下加载<sup>[14](https://blog.apnic.net/2024/10/14/how-to-inspect-tls-encrypted-traffic/)</sup>。自 Wireshark 3.0 起，密钥日志可嵌入 pcapng 文件，使解密密钥随捕获文件一起传输；TLS 解析器从 SSL 更名为 TLS，旧的 `ssl` 过滤器会发出警告<sup>[8](https://wiki.wireshark.org/TLS)</sup>。

该方法有局限。只有 Wireshark 和 TShark 能分析解密后的 TLS 流量，这使得密钥日志方法不适用于使用自定义 TLS 库的恶意软件命令与控制流量，也难以馈送给 IDS。PolarProxy 和 SSLsplit 等 TLS 代理则可将解密流量保存为 PCAP 文件，供其他工具摄取<sup>[14](https://blog.apnic.net/2024/10/14/how-to-inspect-tls-encrypted-traffic/)</sup>。

## 性能限制与捕获策略

Wireshark 与大多数数据包监控应用一样受限于 CPU，性能随分析数据包的数量和性质而下降<sup>[6](https://sharkfest.wireshark.org/retrospective/sfeu/presentations16eu/02.pdf)</sup>。尽管 Wireshark 使用独立进程捕获数据包，但数据包分析是单线程的，从多核系统获益不大<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。当数据包到达速度快于捕获工具读取速度时，捕获库会丢包；缓冲和丢包报告取决于捕获机制<sup>[7](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)</sup>。tcpdump 将同样现象报告为因捕获机制缓冲区空间不足而“被内核丢弃”的数据包<sup>[15](https://www.tcpdump.org/manpages/tcpdump.1.html)</sup>。

这样的数据量不容乐观。在 10 Gbit 线速下，最小尺寸以太网帧每 67 纳秒到达一个；五小时的 10 Gbit 流量约占 24 TB 磁盘<sup>[6](https://sharkfest.wireshark.org/retrospective/sfeu/presentations16eu/02.pdf)</sup>。即使 100 兆比特网络也能在短时间内产生数百兆字节的捕获数据<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。实测结果具体展示了问题：在一台笔记本电脑上，使用 WinPcap 的 Wireshark 在 37.2% 利用率下丢失了 42% 至 52% 的 64 字节帧，而 512 字节帧在 35% 利用率下丢失 0%，但在 50% 利用率下丢失约 11%；专用硬件捕获设备以全线速无丢包捕获，而 tshark 或 Wireshark GUI 报告的丢包计数器被发现很不准确<sup>[16](https://www.profitap.com/wp-content/uploads/ProfiShark-Performance-Results-Tony-Fortunato.pdf)</sup>。

**防丢包调优**遵循一套已知方法：增大捕获缓冲区（默认 2 MiB，可通过 buffer-size 选项以 MiB 为单位设置，但系统或接口可能静默限制），禁用实时数据包列表更新，将抓取长度设为 MTU 加 18 字节，并在 Linux 3.0 及更高版本内核上启用 BPF JIT 以加速内核内捕获过滤<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup><sup> • </sup><sup>[17](https://wiki.wireshark.org/performance)</sup>。减小抓取长度还能降低内存、处理和磁盘占用，并因不保存完整会话内容而有助于保护隐私<sup>[7](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)</sup>。

**仅捕获与离线分析。** 自 0.10.15 版起，dumpcap 可作为仅捕获程序使用，之后运行 Wireshark 或 TShark 进行分析以避免丢包<sup>[17](https://wiki.wireshark.org/performance)</sup>。在高速下，标准替代方案是使用 n2disk 等数据包写盘应用以线速将流量捕获到磁盘，然后让 Wireshark 离线分析 pcap 文件<sup>[6](https://sharkfest.wireshark.org/retrospective/sfeu/presentations16eu/02.pdf)</sup>。如果调优后的捕获仍跟不上，可将流拆分为 N 份，分布在 N 个克隆捕获系统上，每个处理 1/N 的流量<sup>[7](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)</sup>。经同行评审的工作比较了通用硬件上 FreeBSD 和 Linux 的捕获栈，并提供了实现最佳捕获性能的配置指南<sup>[18](https://dl.acm.org/doi/10.1145/1879141.1879168)</sup>。

文件大小也限制交互使用：加载和过滤大于约 100 MB 的捕获文件时，Wireshark 会变慢<sup>[17](https://wiki.wireshark.org/performance)</sup>。

## 与 tcpdump、tshark、Zeek 及商业分析器的比较

各工具分工不同。tcpdump 仅通过命令行操作，而 Wireshark 同时提供 GUI 和命令行组件；管理员常用 tcpdump 进行初步捕获，因为它快速、高效且可配置，并能将数据包写入文件供后续 GUI 分析<sup>[19](https://www.techtarget.com/it-infrastructure/answer/Wireshark-vs-tcpdump-Whats-the-difference)</sup>。TShark 是可脚本化、无 GUI 的对应工具：它从实时网络捕获或读取已保存文件，默认输出与 Wireshark 数据包列表窗格匹配的摘要行，使用详细视图选项则输出每个协议的每个字段<sup>[13](https://linux.die.net/man/1/tshark)</sup>。所有这些工具都共享 pcap 格式传统：Wireshark 的原生格式是 pcapng 和 pcap，而 pcap 是 tcpdump 使用的格式<sup>[3](https://www.wireshark.org/docs/man-pages/wireshark.html)</sup>。

Zeek 占据不同的生态位。其默认数据包源使用 libpcap 读取 PCAP 文件或嗅探接口，然后通过协议特定分析器逐层处理数据包，在应用层使用动态协议检测<sup>[20](https://docs.zeek.org/en/new-tutorial/frameworks/packet-analysis.html)</sup>。用 Wireshark 进行数据包分析缺乏高级自动化且可能耗时，这推动了预定义规则自动化的努力<sup>[21](https://dl.acm.org/doi/fullHtml/10.1145/3564721.3565952)</sup>。

## 实际用途

项目自身文档列出了用户群体：网络管理员用它排查网络问题，安全工程师检查安全问题，QA 工程师验证网络应用，开发者调试协议实现<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。具体而言，用户将实时流量捕获到 pcap 文件，应用过滤器，显示数据包头，查看会话和流量统计，并导出对象以供进一步分析<sup>[21](https://dl.acm.org/doi/fullHtml/10.1145/3564721.3565952)</sup>。在安全工作中，已发表的从业者文献涵盖使用 Wireshark 识别网络入侵、即使加密也能发现网络数据、分析恶意软件命令与控制通信并识别入侵指标，以及提取文件数据等对象以支持取证调查<sup>[22](https://link.springer.com/book/10.1007/978-1-4842-9291-4)</sup>。

在教育领域，研究报告称 Wireshark 提高了 TCP/IP 和网络课程的教学效率与学生兴趣，尽管学生初次使用时觉得有挑战性，需要时间适应界面<sup>[21](https://dl.acm.org/doi/fullHtml/10.1145/3564721.3565952)</sup>。它也被用作考核单元：在一个模块中，学生调查了一个包含 Emotet 攻击证据的 pcap 文件，并记录发现和建议<sup>[21](https://dl.acm.org/doi/fullHtml/10.1145/3564721.3565952)</sup>。厂商支持团队将数据包捕获视为深度故障排查的基本诊断步骤，能在数据包层面揭示 DNS、HTTP、ping 及其他流量<sup>[23](https://www.cisco.com/c/en/us/support/docs/security/umbrella/225250-capture-and-analyze-network-traffic.html)</sup>。

## Wireshark 自身的安全与负责任捕获

Wireshark 解析不受信任的数据，各版本会修复漏洞：Wireshark 4.6.5 修复了项目所称的相当多漏洞，并将其归因于近期 AI 辅助漏洞报告的趋势<sup>[24](https://www.wireshark.org/update/relnotes/wireshark-4.6.5.html)</sup>。

捕获文件本身携带敏感内容。由于数据包捕获常包含个人身份信息，应仅通过安全方式共享<sup>[23](https://www.cisco.com/c/en/us/support/docs/security/umbrella/225250-capture-and-analyze-network-traffic.html)</sup>。该工具的被动设计反映了其作为测量工具的角色，因为它测量流量而非与之交互<sup>[1](https://www.wireshark.org/docs/wsug_html/index.html)</sup>。

## 近期版本

自 2023 年底以来的显著变化包括以下内容。Wireshark 4.6.0 放弃 WinPcap 支持，引导 Windows 用户使用 Npcap，并告知必要时卸载 WinPcap<sup>[9](https://lists.wireshark.org/archives/wireshark-users/202605/msg00005.html)</sup>。同一版本新增“绘图”对话框提供散点图，与基于直方图的“I/O 图表”对话框形成对比；新增在存在 NTS-KE 数据包和 TLS 客户端或导出器密钥时使用 NTS 进行 NTP 解密；扩展 [MACsec](https://www.edgepedia.org/zh/macsec) 解密，可使用由 MKA 解析器解包的 SAK 或配置的 PSK；使 macOS 安装程序通用化（Arm64 加 Intel）；并允许实时捕获在写入时压缩<sup>[9](https://lists.wireshark.org/archives/wireshark-users/202605/msg00005.html)</sup>。维护版本持续更新众多解析器的协议支持；4.6.5 版更新了包括 BGP、DNS、HTTP、HTTP2、ICMPv6、IPv4/IPv6、ISAKMP、LDAP、Modbus、MySQL、NGAP、OpenVPN、QUIC、SMB2、SSH 和 [WebSocket](https://www.edgepedia.org/zh/websocket) 在内的解析器，其 Windows 安装程序附带 Npcap 1.87 和 Qt 6.10.3<sup>[24](https://www.wireshark.org/update/relnotes/wireshark-4.6.5.html)</sup>。

## References

1. [Wireshark User's Guide, Wireshark Foundation](https://www.wireshark.org/docs/wsug_html/index.html)
2. [Protocol Reverse-Engineering Methods and Tools: A Survey, Computer Communications Vol. 182 (2021)](https://dl.acm.org/doi/10.1016/j.comcom.2021.11.009)
3. [wireshark(1) man page, Wireshark Foundation](https://www.wireshark.org/docs/man-pages/wireshark.html)
4. [Chappell University Student Manual (Wireshark courseware)](https://www.chappell-university.com/_files/ugd/fe341d_dcd2371b7420406ebf0789bddeb76f30.pdf)
5. [DisplayFilters, Wireshark GitLab Wiki](https://gitlab.com/wireshark/wireshark/-/wikis/DisplayFilters)
6. [High-speed packet capture presentation, SharkFest '16 Europe](https://sharkfest.wireshark.org/retrospective/sfeu/presentations16eu/02.pdf)
7. [Improving packet capture performance: measuring the problem, APNIC Blog (2020)](https://blog.apnic.net/2020/11/02/improving-packet-capture-performance-measuring-the-problem/)
8. [TLS, Wireshark Wiki](https://wiki.wireshark.org/TLS)
9. [Wireshark 4.6.6 released, wireshark-users mailing list](https://lists.wireshark.org/archives/wireshark-users/202605/msg00005.html)
10. [the-tcpdump-group/libpcap, GitHub](https://github.com/the-tcpdump-group/libpcap)
11. [A Complete Guide to Network Packet Capture, Network Critical](https://www.networkcritical.com/blogs/a-complete-guide-to-network-packet-capture)
12. [Wireshark Network Analysis, Second Edition (WCNA Study Guide)](https://elhacker.info/manuales/Redes/wireshark-network-analysis-second-edition.pdf)
13. [tshark(1): Dump/analyze network traffic, Linux man page](https://linux.die.net/man/1/tshark)
14. [How to inspect TLS encrypted traffic, APNIC Blog (2024)](https://blog.apnic.net/2024/10/14/how-to-inspect-tls-encrypted-traffic/)
15. [tcpdump(1) man page, tcpdump.org](https://www.tcpdump.org/manpages/tcpdump.1.html)
16. [ProfiShark Performance Results, Tony Fortunato](https://www.profitap.com/wp-content/uploads/ProfiShark-Performance-Results-Tony-Fortunato.pdf)
17. [Performance, Wireshark Wiki](https://wiki.wireshark.org/performance)
18. [Comparing and improving current packet capturing solutions based on commodity hardware, ACM IMC 2010](https://dl.acm.org/doi/10.1145/1879141.1879168)
19. [Wireshark vs. tcpdump: What's the difference?, TechTarget](https://www.techtarget.com/it-infrastructure/answer/Wireshark-vs-tcpdump-Whats-the-difference)
20. [Packet Analysis, Book of Zeek](https://docs.zeek.org/en/new-tutorial/frameworks/packet-analysis.html)
21. [Network Packet Analysis as a Unit of Assessment: Identifying Emotet, ACM](https://dl.acm.org/doi/fullHtml/10.1145/3564721.3565952)
22. [Tactical Wireshark, Apress/Springer](https://link.springer.com/book/10.1007/978-1-4842-9291-4)
23. [Capture and Analyze Network Traffic with Wireshark for Diagnostics, Cisco](https://www.cisco.com/c/en/us/support/docs/security/umbrella/225250-capture-and-analyze-network-traffic.html)
24. [Wireshark 4.6.5 Release Notes, Wireshark Foundation](https://www.wireshark.org/update/relnotes/wireshark-4.6.5.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Networking fundamentals and architecture

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/wireshark

English original: https://www.edgepedia.org/wireshark
