当前位置:网站首页>【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
}
}
边栏推荐
- 非技术部门,如何参与 DevOps?
- vscode的快捷键
- Events and bubbles in the applet of "wechat applet - Basics"
- mongoDB副本集
- “军备竞赛”时期的对比学习
- Have you learned to make money in Dingding, enterprise micro and Feishu?
- Implementation of wechat applet bottom loading and pull-down refresh
- How did automated specification inspection software develop?
- 【SWT组件】内容滚动组件 ScrolledComposite
- [paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
猜你喜欢
5G NR系统架构
Who is the "conscience" domestic brand?
Workmanager learning 1
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
Swift tableview style (I) system basic
【黑马早报】罗永浩回应调侃东方甄选;董卿丈夫密春雷被执行超7亿;吉利正式收购魅族;华为发布问界M7;豆瓣为周杰伦专辑提前开分道歉...
[paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
Fluent generates icon prompt logo widget
@SerializedName注解使用
How to write high-quality code?
随机推荐
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
"Everyday Mathematics" serial 58: February 27
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
IDEA新建sprintboot项目
Solution of ellipsis when pytorch outputs tensor (output tensor completely)
In wechat applet, after jumping from one page to another, I found that the page scrolled synchronously after returning
“军备竞赛”时期的对比学习
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
leetcode:1200. 最小绝对差
Interview: how does the list duplicate according to the attributes of the object?
Node の MongoDB Driver
Flink CDC cannot monitor MySQL logs. Have you ever encountered this problem?
一个可以兼容各种数据库事务的使用范例
Pseudo class elements -- before and after
App各大应用商店/应用市场网址汇总
学习笔记4--高精度地图关键技术(下)
QT VT100 parser
字节跳动面试官:一张图片占据的内存大小是如何计算
[vite] 1371 - develop vite plug-ins by hand
mongoDB副本集