通过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以及它们访问的次数打印了出来

转载于:https://www.cnblogs.com/-abm/p/9713223.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值