dkorunic/pktstat

GitHub: dkorunic/pktstat

一个轻量级的跨平台网络流量监控工具,可实时统计并报告各 IP 和协议的带宽使用情况。

Stars: 94 | Forks: 4

# pktstat [![GitHub license](https://img.shields.io/github/license/dkorunic/pktstat)](https://github.com/dkorunic/pktstat/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/dkorunic/pktstat)](https://github.com/dkorunic/pktstat/releases/latest) ![](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/13e42eed4e184215.png) ## 关于 pktstat 是基于 ncurses 的 [pktstat](https://github.com/dleonard0/pktstat) 的轻量级替代品。在 Linux 上,它使用 [AF_PACKET](https://doc.dpdk.org/guides/nics/af_packet.html);在所有其他平台上,它使用通用的实时 PCAP 捕获。它不需要特殊或最新的内核特性 —— `AF_PACKET` 自 Linux **v2.2** (1999) 起就已可用 —— 并且完全兼容其他 Unix 平台(如 Darwin),在这些平台上它会回退到通用 PCAP。 执行结束时,程序会显示每个 IP 和每个协议的统计信息(IPv4、IPv6、TCP、UDP、ICMPv4 和 ICMPv6),并按每个连接的 bps、数据包计数和(源 IP:端口 → 目标 IP:端口)元组进行排序。 ![Demo](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/4e7b0248ec184216.gif) ## 系统要求 捕获流量通常需要 root 权限。作为替代方案,您可以在授予必要的 Linux [capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html) 后,以普通用户身份运行 pktstat: ``` $ setcap cap_net_raw,cap_net_admin=eip pktstat ``` ## 用法 ``` ➜ ./pktstat --help NAME pktstat FLAGS -?, --help display help -v, --add_vlan if true, add VLAN header -j, --json if true, output in JSON format --version display program version -s, --snaplen INT snaplen (if <= 0 uses 65535) (default: 0) -b, --bufsize INT interface buffersize in MB (default: 8) -f, --filter STRING BPF filter -i, --iface STRING interface to read from (default: en0) -t, --timeout DURATION timeout for packet capture (default: 10m0s) -l, --interval DURATION interval between packet capture output (default: 0s) ``` 默认情况下,pktstat 会监听所有接口且不应用 BPF 过滤器。使用 `--iface` 选择特定接口,使用 `--filter` 限制捕获的流量 —— 例如,`--filter "not port 22"` 用于排除 SSH 流量。 `--timeout` 会在指定的持续时间后停止捕获。您也可以随时使用 Ctrl-C、SIGTERM 或 SIGINT 中断程序。 `--json` 将流量统计信息输出为 JSON,而不是纯文本。 当 `--interval` 设置为大于零且小于超时时间的值时,程序将按该间隔打印统计信息,直到退出。 ## Star 历史 [![Star History Chart](https://api.star-history.com/svg?repos=dkorunic/pktstat,dkorunic/pktstat-bpf&type=Date)](https://star-history.com/#dkorunic/pktstat&dkorunic/pktstat-bpf&Date)
标签:AF_PACKET, API安全, BPF过滤器, EVTX分析, GitHub搜索工具, Go语言, IPv4/IPv6统计, JSON输出, PCAP, TCP/UDP流量, 以太网接口, 协议分析, 带宽监测, 性能监控, 报文统计, 日志审计, 权限提升, 程序破解, 网络分析工具, 网络可见性, 轻量级工具, 运维工具, 进程隐藏, 防御绕过