通過shell查找訪問日志中訪問量最大的ip


日志格式:

101.231.147.230 - - [27/Sep/2018:11:12:15 +0800] "POST /reloadProjectList.action?projectPage=18 HTTP/1.1" 200 848
210.205.3.195 - - [27/Sep/2018:11:12:15 +0800] "POST //reloadProjectList.action?projectPage=24 HTTP/1.1" 200 848
80.82.70.187 - - [27/Sep/2018:11:12:17 +0800] "GET /cache/global/img/gs.gif HTTP/1.1" 302 -
210.205.3.195 - - [27/Sep/2018:11:12:18 +0800] "GET /psp2/image/aniu_03.gif HTTP/1.1" 304 -
66.249.69.89 - - [27/Sep/2018:11:12:20 +0800] "GET /picUpload/project/201003105/201003105src/swf/images/wallpaper03.gif?2782468 HTTP/1.1" 404 1142
210.205.3.195 - - [27/Sep/2018:11:12:21 +0800] "GET /psp2/image/aniu_03.gif HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:22 +0800] "GET / HTTP/1.1" 200 53318
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /psp2/css/reset.css HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /psp2/css/index.css HTTP/1.1" 304 -
211.152.37.8 - - [27/Sep/2018:11:12:23 +0800] "GET / HTTP/1.1" 302 -
210.205.3.195 - - [27/Sep/2018:11:12:23 +0800] "POST /reloadProjectList.action?projectPage=10 HTTP/1.1" 200 608
211.152.37.8 - - [27/Sep/2018:11:12:23 +0800] "GET / HTTP/1.1" 200 53318
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /public/js/common.js HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /psp2/js/jquery_min.js HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /public/js/app/CaeeResources_zh_CN.js HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /jwplayer/jwplayer.js HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:23 +0800] "GET /psp2/image/share_01.png HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:24 +0800] "GET /psp2/image/share_02.png HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:24 +0800] "GET /psp2/image/share_03.png HTTP/1.1" 304 -
101.231.147.230 - - [27/Sep/2018:11:12:24 +0800] "GET /psp2/image/head1.png HTTP/1.1" 304 -

命令:

[root@GGFW-nginx ~]# awk '{print $1}' localhost_access_log.2018-09-27.txt | sort -nr | uniq -c | sort -nr | head -20

ps:awk '{print $1}' localhost_access_log.2018-09-27.txt  //表示篩選ip

  sort -rn 排序 ,n表示用數字大小排序,r表示反向排序,這里排序是為了使用uniq

  uniq -c 去重,相比於“sort -u”  uniq只去重相鄰的重復

4801 122.228.10.56
3985 210.205.3.195
2563 101.231.147.230
2091 211.152.37.8
1167 122.228.10.59
697 192.168.10.120
566 106.120.124.4
278 223.166.174.15
257 60.6.212.91
251 204.12.226.26
231 211.149.217.113
220 117.136.8.229
215 112.17.88.223
210 183.61.165.66
208 216.244.66.238
200 61.164.81.194
194 43.243.12.243
182 66.249.71.27
161 61.153.249.186
145 173.208.206.50

以上將訪問次數最多的20個ip以及它們訪問的次數打印了出來


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM