#!/bin/bash
#writen by simon @20140325
filesource=mysql.log
output=denied.ip`date ‘+%Y%m%d’`
ipp (){
exec < $1
tring_times=0
while read a
do
columns=`echo $a|awk -F’ ‘ ‘{print NF; exit}’`
if [ ! $columns -eq ‘2’ ];then
continue
fi
sourceip=`echo $a |awk -F’ ‘ ‘{print $2}’`
ipcount=`echo $a|awk -F’ ‘ ‘{print $1}’`
sring=`curl -s “http://ip138.com/ips138.asp?ip=${sourceip}&action=2"| iconv -f gb2312 -t utf-8|grep ‘

  • ‘ | awk -F ‘[<> ]+’ ‘{print substr($7,7)}’ echo $sourceip $sring $ipcount' 次' done } grep denied $filesource | awk -F' ' '{print $7}' |sort|awk -F"'" '{print $4}' | uniq -c > /tmp/ip.source #for mac only sed -i '' '$d' /tmp/ip.source #for other linux #sed -i '$d' /tmp/ip.source if \[ ! -f denied \];then touch $output fi echo \date ‘+—%Y%m%d—‘` >> $output
    ipp /tmp/ip.source |tee -a $output
    ipcount=`wc -l /tmp/ip.source`
    echo ‘共尝试连接 ‘`awk -F’ ‘ ‘BEGIN{t=0} {t+=$1} END{print t}’ /tmp/ip.source`‘ 次’ >> $output
    echo ‘来自’$ipcount’个ip’ >> $output
    rm /tmp/ip.source