#!/bin/bash # # This script builds report in form of "Hits CountryCode" # Usage: bycc # #set -x EXCLUDE="(104.245.101.69|31.220.15.193|195.191.214.202)" debot < $1 | egrep -v $EXCLUDE > 1.log cut -d' ' -f 1 1.log | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -c | sed -e "s/^\s*//" -e "s/ /,/" | sort -nr > ips.txt rm -f hitsbyip.txt for i in `cat ips.txt `; do hits=`echo $i | cut -d',' -f 1` ip=`echo $i | cut -d',' -f 2` cc=`geoiplookup $ip | grep Country | cut -d' ' -f 4 | tr -d ','`; echo $hits $cc $ip >> hitsbyip.txt done cut -d' ' -f 2 hitsbyip.txt | sort | uniq > ccs.txt for i in `cat ccs.txt `; do hits=0; for j in `grep " $i " hitsbyip.txt | cut -d' ' -f 1`; do hits=$(($hits+$j)); done echo $hits $i; done | sort -n -r > hitsbycc.txt rm -f 1.log cat hitsbycc.txt