返回更新列表
新发布Sep 1, 2026

nDPI v6.0

开源深度包检测软件工具包

分享

nDPI

构建状态 模糊测试状态

什么是 nDPI?

nDPI® 是一个开源的 LGPLv3 深度包检测库。

关于 nDPI 的常见问题解答可参见此处

如何编译 nDPI

编译本项目的步骤如下:

  • ./autogen.sh && ./configure
  • make

如果在编译 croaring.c 时遇到错误,请尝试:

  • ./autogen.sh && ./configure --enable-old-croaring
  • make

若要仅编译库而不包含任何工具或测试:

  • ./autogen.sh && ./configure --with-only-libndpi
  • make

支持树外编译:

  • ./autogen.sh
  • mkdir build
  • cd build
  • ../configure && make

如需执行额外测试,请执行以下命令:

  • ./tests/do.sh # 生成并检查 PCAP 文件中的差异
  • ./tests/do-unit.sh # 运行单元测试
  • ./tests/do-dga.sh # 运行 DGA 检测测试

或一次性运行所有测试:make check

请注意,编译所需的最低前提条件包括:

  • GNU 工具(autoconf automake libtool pkg-config gettext flex bison)
  • GNU C 编译器(gcc)或 Clang

在 Debian/Ubuntu 系统中,请执行:

  • sudo apt-get install build-essential git gettext flex bison libtool autoconf automake pkg-config libpcap-dev libjson-c-dev libnuma-dev libpcre2-dev libmaxminddb-dev librrd-dev

在 Arch Linux 中:

  • sudo pacman -S gcc git gettext flex bison libtool autoconf automake pkg-config libpcap json-c numactl pcre2 libmaxminddb rrdtool

在 FreeBSD 中:

  • sudo pkg install gcc git gettext flex bison libtool autoconf automake devel/pkgconf gmake libpcap json-c pcre2 libmaxminddb rrdtool

在 FreeBSD 上请务必使用 gmake 而非 make

在 MacOS 中:

  • brew install coreutils gcc git gettext flex bison libtool autoconf automake pkg-config libpcap json-c pcre2 libmaxminddb rrdtool

在 Windows 中:

有三种受支持的构建 nDPI 的方式:

  1. MSYS2(假设已安装 MSYS2):
  • msys2 -c "pacman --noconfirm -S --needed --overwrite '*' git mingw-w64-x86_64-toolchain automake1.16 automake-wrapper autoconf libtool make mingw-w64-x86_64-json-c mingw-w64-x86_64-crt-git mingw-w64-x86_64-pcre2 mingw-w64-x86_64-libpcap"
  1. Mingw-w64

  2. Visual Studio(参见 windows/nDPI.sln

注意:所有 Windows 版本都需要启用 WinPcap 兼容模式的 npcap

如何构建文档

  • pip install --upgrade pip
  • pip install -r doc/requirements.txt
  • make doc

使用内置的 Python3 Web 服务器查看文档:

  • make doc-view

如何添加新的协议解析器

以下是添加新协议的完整详细步骤:

  1. src/include/ndpi_protocol_ids.h 中,为新协议添加唯一的 ID。
  2. src/lib/protocols/ 中创建新的协议文件。
  3. 需要在整个流期间保留的变量(作为状态变量)应放置在 src/include/ndpi_typedefs.hndpi_flow_tcp_struct(仅 TCP)、ndpi_flow_udp_struct(仅 UDP)或 ndpi_flow_struct(两者通用)中。
  4. src/include/ndpi_private.h 中,为新协议的搜索函数添加新条目。
  5. src/include/ndpi_define.h 中选择(不做任何更改)一个选择位掩码。
  6. src/lib/ndpi_main.cndpi_init_protocol_defaults 中设置协议的默认端口。
  7. 确保支持 nBPF,在与克隆 nDPI 相同的目录中克隆 PF_RINGgit clone https://github.com/ntop/PF_RING/ && cd PF_RING/userland/nbpf && ./configure && make。可以忽略 /bin/sh: 1: ../lib/pfring_config: not found 错误。
  8. nDPI 根目录执行 ./autogen.sh && ./configure --with-pcre2(nBPF 和 PCRE2 通常为可选,但运行/更新所有单元测试需要它们)。
  9. make
  10. make check
  11. 更新文档,在 doc/protocols.rst 中添加此新协议。
  12. 更新 Windows Visual Studio 配置,在 windows/nDPI.vcxproj 中添加新的 .c 文件。

如何使用 nDPI 阻止选定流量

您可以通过将 nDPI 嵌入到应用程序中来使用它选择性地阻止特定的互联网流量(请记住 nDPI 只是一个库)。ntopngnProbe cento 都可以实现这一点。

nDPI 论文引用

视频与演示

nDPI 相关项目

免责声明

尽管我们尽最大努力检测网络协议,但我们无法保证本软件无错误且协议检测达到 100% 准确。请确保您尊重用户隐私,并获得适当的授权来监听、捕获和检查网络流量。

nDPI 是美国和欧盟的注册商标。

分类