Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Shell counts the current network connection

Shulou Source: shulou.com Published: 2022-06-01 02:30:19 10月04日 Update

When the number of TCP connections is very large, the current internal IP and external IP connections are counted.

[root@lvs02 account_tcp] # cat account_tcp.sh #! / bin/bash# Statistics the current network connection netstat-na | awk'/ ^ tcp/ {s [$6] + +} END {for (key in s) print key S [key]}'> / root/account_tcp/state.txt# statistics on the number of TCP connections in Local Address netstat-na | awk'/ ^ tcp/' | awk-v FS= "[:] +'{print $4}'| sort | uniq-c | sort-n > / root/account_tcp/Local_Address.txt# statistics on TCP connections of Foreign Address with IP 51 netstat-na | awk'/ ^ tcp/' | grep 192.168.10.51 | awk-v FS=" [ :] +'{print $6}'| sort | uniq-c | sort-n > / root/account_tcp/51_tcp.txt# counts the TCP connection of Foreign Address with IP 80 netstat-na | awk'/ ^ tcp/' | grep 192.168.10.80 | awk-v FS= "[:] +'{print $6}'| sort | uniq-c | sort-n > / root/account_tcp/80_tcp.txt# counts Foreign Address with IP of 86 TCP connection netstat-na | awk'/ ^ tcp/' | grep 192.168.10.86 | awk-v FS= "[:] +'{print $6}'| sort | uniq-c | sort-n > / root/account_tcp/86_tcp.txt# statistics netstat-na of Foreign Address whose IP is 87 | awk'/ ^ tcp/' | grep 192.168.10.87 | awk-v FS=" [:] + "{print $6}' | | sort | uniq-c | sort-n > / root/account_tcp/87_tcp.txt |

Tags: Statistics situation network quantity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info macOS Xiaomi Shulou Information