• Stars
    star
    703
  • Rank 64,412 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created about 3 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🤒 A modern alternative network traffic sniffer.

sniffer

GoDoc Go Report Card License

A modern alternative network traffic sniffer inspired by bandwhich(Rust) and nethogs(C++).

sniffer.mov

Introduction

中文介绍

sniffer is designed for network troubleshooting. It can be started at any time to analyze the processes or connections causing increases in network traffic without loading any kernel modules. By the way, the TUI of it is responsive that can fit with terminals of all sizes automatically.

sniffer manipulates gopacket to sniff the interfaces and record packets' info. gopacket wraps the Golang port of libpacp library, and provides some additional features. One of the projects that inspired the sniffer is bandwhich, which has a sophisticated interface and multiple ways to display data, but it does not support BPF filters. Another one is nethlogs, which supports BPF filters, but can only view data by process, without connections or remote address perspective. sniffer combines the advantages of those two projects also adhering a new Plot mode.

Connections and Process Matching

On Linux, sniffer refers to the ways in which the ss tool used, obtaining the connections of the ESTABLISHED state by netlink socket. Since that approach is more efficient than reading the /proc/net/* files directly. But both need to aggregate and calculate the network traffic of the process by matching the inode information under /proc/${pid}/fd.

On macOS, the lsof command is invoked, which relies on capturing the command output for analyzing process connections information. And sniffer manipulates the API provided by gopsutil directly on Windows.

Installation

sniffer relies on the libpcap library to capture user-level packets hence you need to have it installed first.

Linux / Windows

Debian/Ubuntu

$ sudo apt-get install libpcap-dev

CentOS/Fedora

$ sudo yum install libpcap libpcap-devel

Windows

Windows need to have npcap installed for capturing packets.

After that, install sniffer by go get command.

$ go get -u github.com/chenjiandongx/sniffer

MacOS

$ brew install sniffer

Usages

❯ sniffer -h
# A modern alternative network traffic sniffer.

Usage:
  sniffer [flags]

Examples:
  # bytes mode in MB unit
  $ sniffer -u MB

  # only capture the TCP protocol packets with lo,eth prefixed devices
  $ sniffer -b tcp -d lo -d eth

Flags:
  -a, --all-devices                  listen all devices if present
  -b, --bpf string                   specify string pcap filter with the BPF syntax (default "tcp or udp")
  -d, --devices-prefix stringArray   prefixed devices to monitor (default [en,lo,eth,em,bond])
  -h, --help                         help for sniffer
  -i, --interval int                 interval for refresh rate in seconds (default 1)
  -l, --list                         list all devices name
  -m, --mode int                     view mode of sniffer (0: bytes 1: packets 2: plot)
  -n, --no-dns-resolve               disable the DNS resolution
  -u, --unit string                  unit of traffic stats, optional: B, Kb, KB, Mb, MB, Gb, GB (default "KB")
  -v, --version                      version for sniffer

Hotkeys

Keys Description
Space pause refreshing
Tab rearrange tables
s switch next view mode
q quit

Performance

iperf is a tool for active measurements of the maximum achievable bandwidth on IP networks. Next we use this tool to forge massive packets on the lo device.

$ iperf -s -p 5001
$ iperf -c localhost --parallel 40 -i 1 -t 2000

sniffer vs bandwhich vs nethogs

As you can see, CPU overheads bandwhich > sniffer > nethogs, memory overheads sniffer > nethogs > bandwhich.

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 128405 root      20   0  210168   5184   3596 S  31.0   0.3   1:21.69 bandwhich
 128596 root      20   0 1449872  21912   8512 S  20.7   1.1   0:28.54 sniffer
 128415 root      20   0   18936   7464   6900 S   5.7   0.4   0:11.56 nethogs

See what stats they show, sniffer and bandwhich output are very approximate(~ 2.5GB/s). netlogs can only handles packets 1.122GB/s.

sniffer bandwhich nethogs
Upload 2.5GiBps 2.5GiBps 1.12GiBps

View Mode

Bytes Mode: display traffic stats in bytes by the Table widget.

Packets Mode: display traffic stats in packets by the Table widget.

License

MIT ©chenjiandongx

More Repositories

1

mzitu

👧 美女写真套图爬虫(二)
Python
1,041
star
2

magnet-dht

✌️ Python3 BitTorrent DHT crawler
Python
935
star
3

mandodb

🤔 A minimize Time Series Database, written from scratch as a learning project. 从零开始实现一个 TSDB
Go
645
star
4

torrent-cli

🔨 磁力获取器命令行工具
Python
640
star
5

awesome-asyncio-cn

😎 Python Asyncio 精选资源列表,囊括了网络框架,库,软件等资源
Makefile
594
star
6

bili-spider

📺 B 站全站视频信息爬虫
Python
581
star
7

cup-size

👀 关于女性文胸尺码的深入探讨
Python
553
star
8

mmjpg

👩 美女写真套图爬虫(一)
Python
479
star
9

51job-spider

🔎 前程无忧 Python 招聘岗位信息爬取和分析
Python
396
star
10

async-proxy-pool

🔅 Python3 异步爬虫代理池
Python
371
star
11

Github-spider

Github 仓库及用户分析爬虫
Python
251
star
12

kubectl-images

🕸 Show container images used in the cluster.
Go
237
star
13

stackoverflow-spider

📖 爬取 Stackoverflow 100万 条问答并简单分析
Python
206
star
14

pixiv

P 站非会员查看人气作品
Python
185
star
15

soksaccounts

🔥 Shadowsocks 账号爬虫
Python
157
star
16

ginprom

📡 Prometheus metrics exporter for Gin.
Go
151
star
17

how

📝 Impressive Linux commands cheat sheet (Python).
Python
124
star
18

gitv

🤟 A git repos analyzing and visualizing tool built in Rust. 我的开源报告
Rust
123
star
19

yummy-girls

🚜 无他,唯手熟尔
JavaScript
79
star
20

pls

✏️ Impressive Linux commands cheat sheet CLI written in Go.
Go
78
star
21

weekly-email-subscribe

阮一峰技术周刊邮件订阅
Python
76
star
22

prometheus101

📘 Prometheus 折腾笔记
73
star
23

clock

☁️ 须知少时凌云志 曾许人间第一流
Go
72
star
24

HupuLive

🏀 虎扑篮球直播命令行版
Python
70
star
25

oscar

🐶 Next generation building tool for nothing
Go
67
star
26

jianweibo

基于 Python Flask 的微博系统
Python
62
star
27

grogudb

🐸 Grogudb is a KV Database designed for fast write/scan heavy workloads.
Go
58
star
28

pinger

📌 A portable ping library written in Go
Go
57
star
29

yap

🚥 Yet another pinger: A high-performance ICMP ping implementation build on top of BPF technology.
Go
53
star
30

bili-video-rank

🔦 B 站视频各项数据排行榜
JavaScript
42
star
31

fy

🌐 Translate words via command line
Python
37
star
32

photo-gevent

👮 美女写真图爬虫 gevent 版
Python
36
star
33

kubectl-count

🎊 Count resources by kind
Go
36
star
34

Qt

Qt 小项目
C++
32
star
35

wallpaper

zol 手机壁纸爬虫(简单分布式?)
Python
27
star
36

collections

📂 Golang 实现的 collections 模块,灵感来自 Python queue 和 Python collections
Go
27
star
37

pytreemap

🌲 树图渲染命令行工具
Python
26
star
38

make-it-colorful

🎨 使用卷积神经网络给图片上色
25
star
39

photo-asyncio

🙉 美女写真图爬虫 asyncio 版
Python
24
star
40

async-bili-spider

📹 B 站异步爬虫初体验
Python
23
star
41

pyocr

利用 tesseract 解析简单数字验证码图片
Python
20
star
42

lolly

🍭 文字动态图生成工具
Python
18
star
43

youdao-go

📘 Golang 有道词典命令行版
Go
18
star
44

aura

🔔 Aura is an SDK for the monitoring system written in Go with love
Go
16
star
45

hupu-referee-report

🏀 虎扑步行街裁判报告
JavaScript
16
star
46

zhihu-zhuanlan

如何分析一个知乎大 V 的专栏文章
Python
15
star
47

photo-go

👼 美女写真图爬虫 Golang 版
Go
15
star
48

pymysql-connection-pool

pymysql 连接池
Python
14
star
49

pyhtime

🕜 一个用来将 datetime 时间转化成更加人性化的 时间描述字符串的库
Python
13
star
50

tszlist

🔗 tszlist 是一种时序数据线程安全链表
Go
11
star
51

emoji.py

🔍 emoji 表情命令行搜索工具
Python
8
star
52

slipper

🍮 Async HTTP Requests-like library based on Aiohttp
Python
7
star
53

photo-trio

👲 美女写真图爬虫 trio 版
Python
7
star
54

skrskr

🤙 当 Python 遇到大碗面 Freestyle 太 Skr 了
Python
6
star
55

mim-system

利用 flask 实现的数据库小作业网站
Python
6
star
56

kslb

🍬 The missing Service Loadbalance for Kubernetes(Just for fun).
Go
6
star
57

wetalk

📠 wetalk is a chatroom application for coders based on websockets
Go
5
star
58

pprofsnapshot

🧶 pprofsnapshot makes it easy to download profiling data to local.
Go
5
star
59

dockerstats

🐳 The easy way to collect docker stats.
Go
4
star
60

gh-contributors

🔖 Github 项目贡献者 Markdown 文档表格生成工具
Python
3
star
61

memcached-collector

📤 Collect metrics from memcached servers using aura.
Go
3
star
62

logger

⚡ A lightweight, auto-rolling logger for Go.
Go
3
star
63

docs-need-space

📗 文档空格检查工具
Python
3
star
64

grogudb-benchmark

grogudb benchmark project
Go
1
star