zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Linux连接数

2023-02-18 16:45:08 时间
  1. 统计已建立的连接数
[root@orderer ~]# netstat -ntap | grep ESTABLISHED | wc -l
232
  1. 统计某个端口的连接数
[root@orderer ~]# netstat -nat|grep -i "27018"|wc -l
35
  1. 统计TCP不同状态的连接数
[root@orderer ~]# netstat -na | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
LISTEN 60
CLOSE_WAIT 20
ESTABLISHED 227
FIN_WAIT2 13
TIME_WAIT 140
  1. 对已建立的tcp连接且对目标地址的端口号进行连接数的统计,且连接数大于1,并按端口号排序输出
[root@orderer ~]# netstat -nat | grep ESTABLISHED | awk '{print $5}'| awk -F: '{print $2}' | awk '{++S[$NF]} END {for(a in S)print a,S[a]}'|awk '$2>1 {print $1,$2}'|sort -n
443 3
3306 45
7050 2
8199 18
9092 9
27017 28
27018 222
45506 2