文章目录
netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n<=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf("%-20s %s\n", a, S[a]);++I}printf("%-20s %s\n","TOTAL_IP",I);for(a in s) printf("%-20s %s\n",a, s[a]);printf("%-20s %s\n","TOTAL_LINK",N);}'
[root@master ~]#netstat -n | awk '/^tcp/ {n=split($(NF-1),array,":");if(n<=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf("%-20s %s\n", a, S[a]);++I}printf("%-20s %s\n","TOTAL_IP",I);for(a in s) printf("%-20s %s\n",a, s[a]);printf("%-20s %s\n","TOTAL_LINK",N);}'
42334 1
6443 1
192.168.10.1 1
192.168.10.65 16
192.168.10.66 3
192.168.10.67 3
127.0.0.1 161
10.96.0.1 1
10.244.0.10 1
10.244.0.8 1
TOTAL_IP 10
ESTABLISHED 183
TIME_WAIT 6
TOTAL_LINK 189
观察主机系统日志
[root@master ~]#dmesg -T | tail -n 10
[Tue Jul 12 15:04:05 2022] device vetha2622729 entered promiscuous mode
[Tue Jul 12 15:04:05 2022] cni0: port 2(vetha2622729) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 2(vetha2622729) entered forwarding state
[Tue Jul 12 15:04:05 2022] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[Tue Jul 12 15:04:05 2022] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered disabled state
[Tue Jul 12 15:04:05 2022] device veth9515c149 entered promiscuous mode
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered blocking state
[Tue Jul 12 15:04:05 2022] cni0: port 3(veth9515c149) entered forwarding state