当前位置:网站首页>【tcp】服务器上tcp连接状态json形式输出
【tcp】服务器上tcp连接状态json形式输出
2022-07-05 10:18:00 【HunterMichaelG】
print_tcp_conection.sh
#!/bin/bash
STATS=(UNKNOWN:0 ESTABLISHED:0 SYN_SENT:0 SYN_RECV:0 FIN_WAIT1:0 FIN_WAIT2:0 TIME_WAIT:0 CLOSED:0 CLOSE_WAIT:0 LAST_ACK:0 LISTEN:0 CLOSING:0)
CONN="$(awk '{print $4}' /proc/net/tcp /proc/net/tcp6 | grep -v st | sort | uniq -c | sed -e s/' 0'/' '/g -e s/'A'/'10'/g -e s/'B'/'11'/g | awk '{print $2":"$1}')"
if [ ! -z "$CONN" ];then
for s in $CONN
do
STATS[${s%%:*}]=${STATS[${s%%:*}]%%:*}":"${s#*:}
done
fi
echo ${STATS[@]} | sed -e s/' '/',"'/g -e s/':'/'":'/g -e s/^/'{"tcp_conn":{"'/g -e s/'WAIT_'/'WAIT'/g -e s/'$'/'}}'/g
# sh print_tcp_conection.sh
{"tcp_conn":{"UNKNOWN":0,"ESTABLISHED":4,"SYN_SENT":0,"SYN_RECV":0,"FIN_WAIT1":0,"FIN_WAIT2":0,"TIME_WAIT":0,"CLOSED":0,"CLOSE_WAIT":0,"LAST_ACK":0,"LISTEN":6,"CLOSING":0}}
# sh print_tcp_conection.sh | python -m json.tool
{
"tcp_conn": {
"CLOSED": 0,
"CLOSE_WAIT": 0,
"CLOSING": 0,
"ESTABLISHED": 4,
"FIN_WAIT1": 0,
"FIN_WAIT2": 0,
"LAST_ACK": 0,
"LISTEN": 6,
"SYN_RECV": 0,
"SYN_SENT": 0,
"TIME_WAIT": 0,
"UNKNOWN": 0
}
}
边栏推荐
- How to plan the career of a programmer?
- Singleton mode encapsulates activity management class
- 学习笔记4--高精度地图关键技术(下)
- Learning note 4 -- Key Technologies of high-precision map (Part 2)
- In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
- Constraintlayout officially provides rounded imagefilterview
- 重磅:国产IDE发布,由阿里研发,完全开源!
- Excerpt from "sword comes" (VII)
- 《剑来》语句摘录(七)
- Learning notes 5 - high precision map solution
猜你喜欢

Advanced opencv:bgr pixel intensity map

AD20 制作 Logo

Apple 5g chip research and development failure? It's too early to get rid of Qualcomm

Uni app running to wechat development tool cannot Preview

Have you learned to make money in Dingding, enterprise micro and Feishu?

Learning II of workmanager

钉钉、企微、飞书学会赚钱了吗?

How can non-technical departments participate in Devops?

Learning Note 6 - satellite positioning technology (Part 1)

Secteur non technique, comment participer à devops?
随机推荐
Qt实现json解析
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
flink cdc不能监听mysql日志,大家遇到过这个问题吧?
SAP ui5 objectpagelayout control usage sharing
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
How to judge that the thread pool has completed all tasks?
请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
Window下线程与线程同步总结
Using directive in angualr2 to realize that the picture size changes with the window size
Coneroller执行时候的-26374及-26377错误
想请教一下,十大券商有哪些?在线开户是安全么?
WorkManager的学习二
isEmpty 和 isBlank 的用法区别
Secteur non technique, comment participer à devops?
AD20 制作 Logo
Shortcut keys for vscode
最全是一次I2C总结
非技術部門,如何參與 DevOps?
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题