当前位置:网站首页>【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
}
}
边栏推荐
- AtCoder Beginner Contest 258「ABCDEFG」
- Usage differences between isempty and isblank
- 《通信软件开发与应用》课程结业报告
- How do programmers live as they like?
- How can non-technical departments participate in Devops?
- Workmanager Learning one
- Implementation of wechat applet bottom loading and pull-down refresh
- AtCoder Beginner Contest 258「ABCDEFG」
- 学习笔记5--高精地图解决方案
- Swift saves an array of class objects with userdefaults and nssecurecoding
猜你喜欢
![[vite] 1371 - develop vite plug-ins by hand](/img/7f/84bba39965b4116f20b1cf8211f70a.png)
[vite] 1371 - develop vite plug-ins by hand

到底谁才是“良心”国产品牌?
![C language QQ chat room small project [complete source code]](/img/4e/b3703ac864830d55c824e1b56c8f85.png)
C language QQ chat room small project [complete source code]

重磅:国产IDE发布,由阿里研发,完全开源!

What is the most suitable book for programmers to engage in open source?

Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "

ConstraintLayout官方提供圆角ImageFilterView

How do programmers live as they like?

> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复

Advanced opencv:bgr pixel intensity map
随机推荐
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
Ad20 make logo
5G NR系统架构
Completion report of communication software development and Application
Timed disappearance pop-up
Pseudo class elements -- before and after
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
Error: module not found: error: can't resolve 'xxx' in 'XXXX‘
橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
@Serializedname annotation use
@Jsonadapter annotation usage
Should the dependency given by the official website be Flink SQL connector MySQL CDC, with dependency added
Workmanager learning 1
Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
Learning II of workmanager
报错:Module not found: Error: Can‘t resolve ‘XXX‘ in ‘XXXX‘
C#实现获取DevExpress中GridView表格进行过滤或排序后的数据
学习笔记6--卫星定位技术(上)