Tomcat? localhost_access_log.2018-09-19.txt log file Access IP statistics
172.16.8.11--[19/sep/2018:12:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.1--[19/sep/2018:12:43:08 +0800] "get/images/loading.gif http/1.1" 200 404
172.16.8.1--[19/sep/2018:12:43:08 +0800] "Post/init http/1.1" 200 207
172.16.8.1--[19/sep/2018:12:43:12 +0800] "Post/init http/1.1" 200 207
172.16.8.1--[19/sep/2018:12:43:16 +0800] "get/http/1.1" 200 7612
172.16.8.1--[19/sep/2018:12:43:16 +0800] "get/css/default-init.css?1537325099834 http/1.1" 304-
172.16.8.1--[19/sep/2018:12:43:16 +0800] "Get/js/lib/jquery/jquery.min.js http/1.1" 304-
172.16.8.1--[19/sep/2018:12:43:16 +0800] "Get/images/logo.png http/1.1" 304-
172.16.8.11--[19/sep/2018:12:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:12:55:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:13:05:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:13:15:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:25:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
172.16.8.11--[19/sep/2018:13:55:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:05:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:15:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:25:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:35:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7612
172.16.8.11--[19/sep/2018:14:45:21 +0800] "Get/console/stat/onlinevisitorrefresh http/1.1" 200 7613
Shell Script
[[email protected] logs]# awk ' {aaa[$1]++;} End{for (i in AAA) {printf ("%s\t%s\n", Aaa[i], i);}} ' Localhost_access_log.2018-09-19.txt | Sort-bn
2?? ? 127.0.0.1
24?? ? 172.16.8.1
26?? ? 172.16.8.11
[[email protected] logs]# grep-i-o-e-r-e "([0-9]{1,3}.) {3} [0-9] {1,3} "Localhost_access_log.2018-09-19.txt | Sort-n | uniq-c | Sort-n
? ? ? 2 127.0.0.1
???? 24 172.16.8.1
???? 26 172.16.8.11
[[email protected] logs]# awk ' {print $} ' localhost_access_log.2018-09-19.txt | Grep-e "([0-9]{1,3}.) {3} [0-9] {1,3} "| Sort | uniq-c | Sort-g
? ? ? 2 127.0.0.1
???? 24 172.16.8.1
???? 26 172.16.8.11
Python script
Cat log.py?
Import re
Mydict = {}
With open (' Localhost_access_log.2018-09-19.txt ') as F:
? ? ? ? For line in F:
? ? ? ? ? ? ? ? Match = Re.match (R ' ([0-9]{1,3}.) {3} [0-9] {1,3} ', line)
? ? ? ? ? ? ? ? If match:
? ? ? ? ? ? ? ? ? ? ? ? ip = Match.group ()
? ? ? ? ? ? ? ? ? ? ? ? If IP in Mydict.keys ():
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MYDICT[IP] + = 1
? ? ? ? ? ? ? ? ? ? ? ? Else
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MYDICT[IP] = 1
Print Mydict
Execution results
[email protected] logs]# python log.py?
{' 172.16.8.1 ': 24, ' 172.16.8.11 ': 27, ' 127.0.0.1 ': 2}
Tomcat log file Access IP statistics