各种日志分析收集中
一、关于IP和流量
1.统计access.log文件中每个ip地址出现的次数
awk '{arr[$1]++;}END{for(i in arr){print i , arr[i] }}' access.log | column -t | sort -nrk2
2.统计access.log中每个ip地址使用的流量总数
awk '{arr[$1]+=$10;}END{for(i in arr){print i , arr[i] }}' access.log | column -t | sort -nrk2
3.通过awk同时分析access.log文件每个ip的重复数和每个ip使用的流量
awk '{count[$1]++;sum[$1]+=$10}END{for(pol in sum)print "ip:"pol,"次数:"count[pol],"流量:"sum[pol]}' access.log
ip:101.226.61.184 次数:5 流量:53581
ip:27.154.190.158 次数:2 流量:31602
ip:218.79.64.76 次数:2 流量:36438
ip:114.94.29.165 次数:1 流量:491
二、关于密码
1.通过awk分析secure这个日志哪个ip地址在破解你的密码?
awk '/Failed password/{h[$(NF-3)]++}END{for(i in h)print i,h[i]}' /var/log/secure | column -t | sort -nrk2 | head
2.通过awk同时分析出secure文件中每个用户被每个ip破解的次数?
awk '/Failed password/{h[$(NF-5)" "$(NF-3)]++}END{for(pol in h) print pol,h[pol]"次"}' /var/log/secure | column -t | sort -nrk3 | head
三、关于网站
1.将域名取出并根据域名进行计数排序处理?
案例:
cat >> url.txt <<EOF
http://www.etiantian.org/index.html
http://www.etiantian.org/1.html
http://post.etiantian.org/index.html
http://mp3.etiantian.org/index.html
http://www.etiantian.org/3.html
http://post.etiantian.org/2.html
EOF
awk -F [:/.]++ '{h[$2]++}END{for(i in h) print i,h[i]}' url.txt | column -t | sort -nrk2