生活随笔
收集整理的這篇文章主要介紹了
Linux 进程、端口、IP、连接数等查询脚本
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
1. 查看TCP連接狀態(tài)
| 1 | netstat?-nat |awk?'{print $6}'|sort|uniq?-c|sort?-rn |
| 2 | netstat?-n |?awk?'/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}' |
| 3 | netstat?-n |?awk?'/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}' |
| 4 | netstat?-n |?awk?'/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}' |
| 5 | netstat?-n |awk?'/^tcp/ {print $NF}'|sort|uniq?-c|sort?-rn |
| 6 | netstat?-ant |?awk?'{print $NF}'?|?grep?-v?'[a-z]'?|?sort?|?uniq?-c |
?(以上每一行實現(xiàn)的效果基本相同,在此列出不同的寫法,方便對腳本寫法的更深理解)
2. 查找請求數(shù)請20個IP(常用于查找攻來源)
| 1 | netstat?-anlp|grep?80|grep?tcp|awk?'{print $5}'|awk?-F:?'{print $1}'|sort|uniq?-c|sort?-nr|head?-n20 |
| 2 | 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嗅探80端口的訪問看看誰最高
| 1 | tcpdump -i eth0 -tnn dst port 80 -c 1000 |?awk?-F"."?'{print $1"."$2"."$3"."$4}'?|?sort?|?uniq?-c |?sort?-nr |head?-20 |
?
4. 查找較多time_wait連接
| 1 | netstat?-n|grep?TIME_WAIT|awk?'{print $5}'|sort|uniq?-c|sort?-rn|head?-n20 |
?
5. 找查較多的SYN連接
| 1 | netstat?-an |?grep?SYN |?awk?'{print $5}'?|?awk?-F:?'{print $1}'?|?sort?|?uniq?-c |?sort?-nr |?more |
?
6. 根據(jù)端口列進程
| 1 | netstat?-ntlp |?grep?80 |?awk?'{print $7}'?|?cut?-d/ -f1 |
7. 查看有多少個PHP-CGI進程活動?
| 1 | netstat?-anp |?grep?php-cgi |?grep?^tcp |?wc?-l |
?
8.查看PHP-CGI占用內(nèi)存的總數(shù)
| 1 | total=0;?for?i?in?`ps?-C php-cgi -o rss=`;?do?total=$(($total+$i));?done;?echo?"PHP-CGI Memory usage: $total kb" |
9.獲得最常用命令的TOP10
| 1 | history?|?awk?'{CMD[$2]++;count++;}END {?for?(a?in?CMD)\ |
| 2 | print CMD[a]?" "?CMD[a]/count*100?"% "?a;}' |?grep?-v?"./"?\ |
| 3 | | column -c3 -s?" "?-t |?sort?-nr |?nl?|?head?-n10 |
轉(zhuǎn)載于:https://my.oschina.net/stefanzhlg/blog/317336
總結(jié)
以上是生活随笔為你收集整理的Linux 进程、端口、IP、连接数等查询脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。