Snitch – 一个对人类友好的 netstat 替代品
Snitch – A friendlier ss/netstat

原始链接: https://github.com/karol-broda/snitch

## Snitch:一款人性化的网络检查工具 Snitch 旨在为检查网络连接提供比 `ss` 和 `netstat` 更易用的替代方案。它提供交互式 TUI(文本用户界面)和带有样式的表格输出,方便分析。 **安装:** Snitch 可以通过 Go (`go install github.com/karol-broda/snitch@latest`)、Nix、软件包管理器(如 `yay` 或 `paru`)或直接安装脚本进行安装。还提供适用于 Linux 和 macOS 的预构建二进制文件。 **用法:** * `snitch`:启动交互式 TUI,显示实时更新的连接列表。 * `snitch ls`:打印带有样式的网络连接表格。选项包括按 `-t`(TCP)、`-l`(监听)、`-e`(已建立)过滤,以及输出格式如 `-p`(纯文本)、`-o json` 或 `-o csv`。 * `snitch watch`:流式传输 JSON 数据,用于脚本编写和监控。 * `snitch upgrade`:检查并安装更新。 TUI 功能包括使用 `j/k` 导航、过滤切换 (`t/u`, `l/e/o`)、进程监视 (`w/W`) 和进程终止 (`K`)。配置选项可通过 `~/.config/snitch/snitch.toml` 访问。 在 Linux 上,Snitch 需要 root 或 CAP_NET_ADMIN 权限才能获取完整的进程信息。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Snitch – 一个对人类友好的 netstat 替代工具 (github.com/karol-broda) 6 分,karol-broda 发布 41 分钟前 | 隐藏 | 过去 | 收藏 | 1 条评论 coppsilgold 8 分钟前 [–] 我一直想知道这类工具对付有能力的对手有多大用处。如果你是一位有能力的工程师,设计恶意软件,难道不会在你的恶意软件可执行文件中引入休眠期,并在可能的情况下只在用户与其他端点通信时才与 C&C 服务器通信吗?甚至可能根据用户正在做的事情选择通信协议,以便更好地融入。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

a friendlier ss / netstat for humans. inspect network connections with a clean tui or styled tables.

snitch demo

go install github.com/karol-broda/snitch@latest
# try it
nix run github:karol-broda/snitch

# install to profile
nix profile install github:karol-broda/snitch

# or add to flake inputs
{
  inputs.snitch.url = "github:karol-broda/snitch";
}
# then use: inputs.snitch.packages.${system}.default
# with yay
yay -S snitch-bin

# with paru
paru -S snitch-bin
curl -sSL https://raw.githubusercontent.com/karol-broda/snitch/master/install.sh | sh

installs to ~/.local/bin if available, otherwise /usr/local/bin. override with:

curl -sSL https://raw.githubusercontent.com/karol-broda/snitch/master/install.sh | INSTALL_DIR=~/bin sh

macos: the install script automatically removes the quarantine attribute (com.apple.quarantine) from the binary to allow it to run without gatekeeper warnings. to disable this, set KEEP_QUARANTINE=1.

download from releases:

  • linux: snitch_<version>_linux_<arch>.tar.gz or .deb/.rpm/.apk
  • macos: snitch_<version>_darwin_<arch>.tar.gz
tar xzf snitch_*.tar.gz
sudo mv snitch /usr/local/bin/

macos: if blocked with "cannot be opened because the developer cannot be verified", run:

xattr -d com.apple.quarantine /usr/local/bin/snitch
snitch              # launch interactive tui
snitch -l           # tui showing only listening sockets
snitch ls           # print styled table and exit
snitch ls -l        # listening sockets only
snitch ls -t -e     # tcp established connections
snitch ls -p        # plain output (parsable)

interactive tui with live-updating connection list.

snitch                  # all connections
snitch -l               # listening only
snitch -t               # tcp only
snitch -e               # established only
snitch -i 2s            # 2 second refresh interval

keybindings:

j/k, ↑/↓      navigate
g/G           top/bottom
t/u           toggle tcp/udp
l/e/o         toggle listen/established/other
s/S           cycle sort / reverse
w             watch/monitor process (highlight)
W             clear all watched
K             kill process (with confirmation)
/             search
enter         connection details
?             help
q             quit

one-shot table output. uses a pager automatically if output exceeds terminal height.

snitch ls               # styled table (default)
snitch ls -l            # listening only
snitch ls -t -l         # tcp listeners
snitch ls -e            # established only
snitch ls -p            # plain/parsable output
snitch ls -o json       # json output
snitch ls -o csv        # csv output
snitch ls -n            # numeric (no dns resolution)
snitch ls --no-headers  # omit headers

json output for scripting.

snitch json
snitch json -l

stream json frames at an interval.

snitch watch -i 1s | jq '.count'
snitch watch -l -i 500ms

check for updates and upgrade in-place.

snitch upgrade              # check for updates
snitch upgrade --yes        # upgrade automatically
snitch upgrade -v 0.1.7     # install specific version

shortcut flags work on all commands:

-t, --tcp           tcp only
-u, --udp           udp only
-l, --listen        listening sockets
-e, --established   established connections
-4, --ipv4          ipv4 only
-6, --ipv6          ipv6 only
-n, --numeric       no dns resolution

for more specific filtering, use key=value syntax with ls:

snitch ls proto=tcp state=listen
snitch ls pid=1234
snitch ls proc=nginx
snitch ls lport=443
snitch ls contains=google

styled table (default):

  ╭─────────────────┬───────┬───────┬─────────────┬─────────────────┬────────╮
  │ PROCESS         │ PID   │ PROTO │ STATE       │ LADDR           │ LPORT  │
  ├─────────────────┼───────┼───────┼─────────────┼─────────────────┼────────┤
  │ nginx           │ 1234  │ tcp   │ LISTEN      │ *               │ 80     │
  │ postgres        │ 5678  │ tcp   │ LISTEN      │ 127.0.0.1       │ 5432   │
  ╰─────────────────┴───────┴───────┴─────────────┴─────────────────┴────────╯
  2 connections

plain output (-p):

PROCESS    PID    PROTO   STATE    LADDR       LPORT
nginx      1234   tcp     LISTEN   *           80
postgres   5678   tcp     LISTEN   127.0.0.1   5432

optional config file at ~/.config/snitch/snitch.toml:

[defaults]
numeric = false
theme = "auto"
  • linux or macos
  • linux: reads from /proc/net/*, root or CAP_NET_ADMIN for full process info
  • macos: uses system APIs, may require sudo for full process info
联系我们 contact @ memedata.com