通过shell查找访问日志中访问量最大的ip

时间:2023-03-09 20:30:30
通过shell查找访问日志中访问量最大的ip

日志格式:

101.231.147.230 - - [/Sep/::: +] "POST /reloadProjectList.action?projectPage=18 HTTP/1.1"
210.205.3.195 - - [/Sep/::: +] "POST //reloadProjectList.action?projectPage=24 HTTP/1.1"
80.82.70.187 - - [/Sep/::: +] "GET /cache/global/img/gs.gif HTTP/1.1" -
210.205.3.195 - - [/Sep/::: +] "GET /psp2/image/aniu_03.gif HTTP/1.1" -
66.249.69.89 - - [/Sep/::: +] "GET /picUpload/project/201003105/201003105src/swf/images/wallpaper03.gif?2782468 HTTP/1.1"
210.205.3.195 - - [/Sep/::: +] "GET /psp2/image/aniu_03.gif HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET / HTTP/1.1"
101.231.147.230 - - [/Sep/::: +] "GET /psp2/css/reset.css HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/css/index.css HTTP/1.1" -
211.152.37.8 - - [/Sep/::: +] "GET / HTTP/1.1" -
210.205.3.195 - - [/Sep/::: +] "POST /reloadProjectList.action?projectPage=10 HTTP/1.1"
211.152.37.8 - - [/Sep/::: +] "GET / HTTP/1.1"
101.231.147.230 - - [/Sep/::: +] "GET /public/js/common.js HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/js/jquery_min.js HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /public/js/app/CaeeResources_zh_CN.js HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /jwplayer/jwplayer.js HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/image/share_01.png HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/image/share_02.png HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/image/share_03.png HTTP/1.1" -
101.231.147.230 - - [/Sep/::: +] "GET /psp2/image/head1.png HTTP/1.1" -

命令:

[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只去重相邻的重复

 122.228.10.56
210.205.3.195
101.231.147.230
211.152.37.8
122.228.10.59
192.168.10.120
106.120.124.4
223.166.174.15
60.6.212.91
204.12.226.26
211.149.217.113
117.136.8.229
112.17.88.223
183.61.165.66
216.244.66.238
61.164.81.194
43.243.12.243
66.249.71.27
61.153.249.186
173.208.206.50

以上将访问次数最多的20个ip以及它们访问的次数打印了出来