⚠️ 自己写:收到了但还没读
本节的 ss 解析小工具(SS_SAMPLE 是真机上 ss -tanp 的原样输出,十行):
parse_ss(text) 一行一个字典:state / recvq / sendq / local / lport / peer / pport / pid(没有进程就是 None)
by_state(rows) {状态: 行数}|listeners(rows) 监听端口列表|peers_of(rows, port) 端口 port 上(Local 是它)的非 LISTEN 连接 [(状态, 对端端口)]State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 1 5 127.0.0.1:25001 0.0.0.0:* users:(("python3",pid=46,fd=3))
LISTEN 0 5 127.0.0.1:25000 0.0.0.0:* users:(("python3",pid=27,fd=3))
TIME-WAIT 0 0 127.0.0.1:31010 127.0.0.1:25002
FIN-WAIT-2 5000 0 127.0.0.1:31001 127.0.0.1:25000 users:(("python3",pid=43,fd=3))
CLOSE-WAIT 1 0 127.0.0.1:25000 127.0.0.1:31001 users:(("python3",pid=27,fd=5))
ESTAB 5 0 127.0.0.1:25001 127.0.0.1:31003
TIME-WAIT 0 0 127.0.0.1:25002 127.0.0.1:31011
ESTAB 0 0 127.0.0.1:31003 127.0.0.1:25001 users:(("python3",pid=49,fd=3))
ESTAB 3976 0 127.0.0.1:31000 127.0.0.1:25000 users:(("python3",pid=30,fd=3))
ESTAB 0 0 127.0.0.1:25000 127.0.0.1:31000 users:(("python3",pid=27,fd=4))Recv-Q 在非 LISTEN 行上是「内核收到了、应用还没 recv 走」的字节数。补全 unread(rows, lport):交回 Local 端口是 lport 的非 LISTEN 行的 Recv-Q 之和。31000 和 31001 两个客户端各多少:
全部评论