linux-shell series 8 netstat usage

1 Check the TCP connection status

netstat -n|awk '{print $6}'|sort|uniq -c|sort -rn

netstat -n|awk '/^tcp/ {++S[$NF]};END{for(a in S)print a,S[a]}'

netstat -n|awk '/^tcp/ {++state[$NF]};END{for(key in state)print key,"\t",state[key]}'

netstat -n|awk '/^tcp/ {++arr[$NF]};END{for(k in arr)print k,"\t",arr[k]}'

netstat -n|awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn

netstat -ant | awk '{print $ NF}' | grep -v '[az]' | sort | uniq -c

2 Find the top 20 IPs by number of requests

netstat -anlp | grep 80 | grep tcp | awk '{print $ 5}' | awk -F: '{print $ 1}' | sort | uniq -c | sort -nr | head -n20

netstat -ant|awk '/:80/ {split($5,ip,":");++A[ip[1]]}END{for(i in A)print A[i],i}'|sort -rn|head -n20

3 tcpdump sniffs access to port 80 to see who has the highest

tcpdump -i eth0 -tnn dst port 80 -c 100|awk -F"." '{print $1"."$2"."$3"."$4}'|sort|uniq -c|sort -rn|head -n20

4 Find more time_wait connections

netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

5 Find more SYN connections

netstat -n|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -rn|more

6 List processes by port

netstat -ntlp|grep 80|awk '{print $7}'|cut -d/ -f1

7 View the total amount of memory occupied by the PHP-cgi process

total=0;for i in `ps -C php-fpm -o rss=`;do total=$(($total+$i));done;echo "PHP-CGI Memory usage: $total kb"

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324777560&siteId=291194637