Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Use awk array to count log access status and network connection status

Shulou Source: shulou.com Published: 2022-06-01 03:26:22 10月06日 Update

Count ip and pv number visited by ip

#awk '{s[$1]++}END{for(key in s) print key,s[key]}' 12.log | sort -k2rn | head

Count the number of connections in various states of the current network

#netstat -na | awk '/^tcp/{s[$6]++}END{for(key in s) print key,s[key]}'

Note: awk also supports filtering/^tcp/filtering lines starting with tcp

Counting IP and connection times currently being established

#netstat -an | grep ESTAB | awk -F "[ :]+" '{print $6}' | sort | uniq -c

#netstat -an | grep "^tcp\>" | awk -F "[ :]+" '{s[$6]++}END{for(key in s) print key,s[key]}'

Count the number of connections in various states

netstat -an | grep "^tcp\>" | awk -F "[ :]+" '{s[$8]++}END{for(key in s) print key,s[key]}'

Tags: Statistics status frequency network function beginning in progress support array log status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info vpn NVidia Docker