#!/bin/bashtc2Linux联盟
#tc2Linux联盟
#---------------------------------------------------------------------------------------tc2Linux联盟
#Scripname:killip,baseonip_conntrack,writebywwy.tc2Linux联盟
#---------------------------------------------------------------------------------------cpu=`sar-u11|awk'{print$7}'|tail-1`tc2Linux联盟
#tc2Linux联盟
while["`pidofsleep`"];dotc2Linux联盟
echo"sheisrunning,sorry"tc2Linux联盟
exit1tc2Linux联盟
donetc2Linux联盟
if[!"`lsmod|grepip_conntrack`"];thentc2Linux联盟
modprobeip_conntracktc2Linux联盟
fi
####################################tc2Linux联盟
##----------------------functions-----------------------------##tc2Linux联盟
####################################
functionmake_clr{tc2Linux联盟
whilereadclr33;dotc2Linux联盟
cat/tmp/tmp111.txt|grep$clr33>>/tmp/tmp33-3-clr.txttc2Linux联盟
done</tmp/tmp33-3.txttc2Linux联盟
whilereadclr22;dotc2Linux联盟
cat/tmp/tmp111.txt|grep$clr22>>/tmp/tmp33-2-clr.txttc2Linux联盟
done</tmp/tmp33-2.txttc2Linux联盟
whilereadclr11;dotc2Linux联盟
cat/tmp/tmp111.txt|grep$clr11>>/tmp/tmp33-1-clr.txttc2Linux联盟
done</tmp/tmp33-1.txttc2Linux联盟
}tc2Linux联盟
functionclr_conns{tc2Linux联盟
S_IP=$1tc2Linux联盟
D_IP=$2tc2Linux联盟
S_PORT=$3tc2Linux联盟
D_PORT=$4tc2Linux联盟
hping2$D_IP-R-s$S_PORT-p$D_PORT-a$S_IP-k-c1>/dev/null2>/dev/null&tc2Linux联盟
}tc2Linux联盟
functionkill(){tc2Linux联盟
SLEEP_TIME=$1tc2Linux联盟
CLR_LIST=$2tc2Linux联盟
BLACK_LIST=$3tc2Linux联盟
whilereadblackip;dotc2Linux联盟
iptables-IFORWARD2-ieth0-s$blackip/32-jDROPtc2Linux联盟
done<$BLACK_LISTtc2Linux联盟
sleep$SLEEP_TIMEtc2Linux联盟
#-----------------------------------#tc2Linux联盟
whilereadclr3;dotc2Linux联盟
clr_conns$clr3tc2Linux联盟
done<$CLR_LISTtc2Linux联盟
#-----------------------------------#tc2Linux联盟
sleep1tc2Linux联盟
whilereadreblackip;dotc2Linux联盟
iptables-DFORWARD-ieth0-s$reblackip/32-jDROPtc2Linux联盟
done<$BLACK_LIST
}tc2Linux联盟
#####################################tc2Linux联盟
##---------------Tomakea"blacklist"----------------------##tc2Linux联盟
#####################################
echo>/tmp/tmp11.txttc2Linux联盟
echo>/tmp/tmp111.txttc2Linux联盟
echo>/tmp/ip_conntrack.tmptc2Linux联盟
echo>/tmp/tmp33-3-clr.txttc2Linux联盟
echo>/tmp/tmp33-2-clr.txttc2Linux联盟
echo>/tmp/tmp33-1-clr.txttc2Linux联盟
echo>/tmp/tmp22-3.txttc2Linux联盟
echo>/tmp/tmp22-2.txttc2Linux联盟
echo>/tmp/tmp22-1.txttc2Linux联盟
echo>/tmp/tmp33-3.txttc2Linux联盟
echo>/tmp/tmp33-2.txttc2Linux联盟
echo>/tmp/tmp33-1.txttc2Linux联盟
if[!-e/var/www/html/wwy/index.html];thentc2Linux联盟
mkdir/var/www/html/wwy/tc2Linux联盟
mkdir/var/www/html/wwy/alltc2Linux联盟
mkdir/var/www/html/wwy/droptc2Linux联盟
5Btc2Linux联盟
touch/var/www/html/wwy/index.htmltc2Linux联盟
fitc2Linux联盟
#----------------------------------------------------------------------------#tc2Linux联盟
echo-e"cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmp......\c"tc2Linux联盟
cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmptc2Linux联盟
echo-e"done!\n"tc2Linux联盟
sleep1tc2Linux联盟
#----------------------------------------------------------------------------#tc2Linux联盟
wc=`cat/tmp/ip_conntrack.tmp|grepESTABLISHED|awk-F='{print$2,$3,$4,$5}'|grep^172.|sort|awk'{print$1,$3,$5,$7}'|tee/tmp/tmp111.txt|awk'{print$1}'|uniq-c|tee/tmp/tmp11.txt|wc-l`tc2Linux联盟
date=`date' m/dH:M'`tc2Linux联盟
cpu2=`sar-u11|awk'{print$7}'|tail-1`tc2Linux联盟
date2=`date' H'`tc2Linux联盟
#----------------------------------------------------------------------------#tc2Linux联盟
sleep1tc2Linux联盟
#----------------------------------------------------------------------------#tc2Linux联盟
#if["$wc"-gt2500]&&["$date2"-gt10]tc2Linux联盟
if["$wc"-ge0]tc2Linux联盟
thentc2Linux联盟
#------------------------------tc2Linux联盟
awk'{$1}{if($1>30&&$1<50)print$2}'/tmp/tmp11.txt>/tmp/tmp22-1.txttc2Linux联盟
awk'{$1}{if($1>=50&&$1<100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-2.txttc2Linux联盟
awk'{$1}{if($1>=100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-3.txttc2Linux联盟
cut-c1-15/tmp/tmp22-1.txt>/tmp/tmp33-1.txttc2Linux联盟
cut-c1-15/tmp/tmp22-2.txt>/tmp/tmp33-2.txttc2Linux联盟
cut-c1-15/tmp/tmp22-3.txt>/tmp/tmp33-3.txttc2Linux联盟
wcblackip1=`cat/tmp/tmp33-1.txt|wc-l`tc2Linux联盟
wcblackip2=`cat/tmp/tmp33-2.txt|wc-l`tc2Linux联盟
wcblackip3=`cat/tmp/tmp33-3.txt|wc-l`
######################################tc2Linux联盟
##----------------Tomakeaindex.html-----------------------##tc2Linux联盟
######################################
echo"<b>IfthetotalIPs>2500<fontcolor=\"#ff0000\">(total$wcat$date)</font>ANDif:</b>">/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<p>youconnect<b>\">100\"</b>,youipwillbekilledin<b>30min</b>.</p>">>/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<p>youconnect<b>\"50-100\"</b>,youipwillbekilledin<b>15min</b>.</p>">>/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<p>youconnect<b>\"30-50\"</b>,youipwillbekilledin<b>10min</b>.</p>">>/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<hrcolor=\"#ff8000\">">>/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<p><b><fontcolor=\"#ff0000\">TheseIPs(total$wcblackip3 $wcblackip2 $wcblackip1)werekilled,at<fontsize=5>$date</font></font><ahref=../all>(look-upallIPs)</a></b></p>">>/var/www/html/wwy/drop/index.htmltc2Linux联盟
awk'{$1}{if($1>=100)print$1,$2}'/tmp/tmp11.txt|sort-nr|awk'{print"<p>""<fontcolor=\"#ff0000\">"$1"</font>""\t","<b>"$2"</b>""\t""kill30min""</p>"}'>>/var/www/html/wwy/drop/index.htmltc2Linux联盟
awk'{$1}{if($1>=50&&$1<100)print$1,$2}'/tmp/tmp11.txt|sort-nr|awk'{print"<p>"$1"\t","<b>"$2"</b>""\t""kill15min""</p>"}'>>/var/www/html/wwy/drop/index.htmltc2Linux联盟
awk'{$1}{if($1>30&&$1<50)print$1,$2}'/tmp/tmp11.txt|sort-nr|awk'{print"<p>"$1"\t","<b>"$2"</b>""\t""kill10min""</p>"}'>>/var/www/html/wwy/drop/index.htmltc2Linux联盟
echo"<p><b>Youcan\"ctrl F\"tofindyourip'sconnects.(total$wcIPsat$date)</b></p>">/var/www/html/wwy/all/index.htmltc2Linux联盟
echo"<p><ahref=../drop><--back</a></p>">>/var/www/html/wwy/all/index.htmltc2Linux联盟
cat/tmp/tmp11.txt|sort-nr|awk'{print"<p>"$1"\t",$2"\t""</p>"}'>>/var/www/html/wwy/all/index.html
#####################################tc2Linux联盟
##-----------------UseiptablestoDROP---------------------##tc2Linux联盟
#####################################
make_clrtc2Linux联盟
if[-s/tmp/tmp33-3.txt];thentc2Linux联盟
kill30m/tmp/tmp33-3-clr.txt/tmp/tmp33-3.txt&tc2Linux联盟
sleep1stc2Linux联盟
fitc2Linux联盟
if[-s/tmp/tmp33-2.txt];thentc2Linux联盟
kill15m/tmp/tmp33-2-clr.txt/tmp/tmp33-2.txt&tc2Linux联盟
sleep1stc2Linux联盟
fitc2Linux联盟
if[-s/tmp/tmp33-1.txt];thentc2Linux联盟
kill10m/tmp/tmp33-1-clr.txt/tmp/tmp33-1.txt&tc2Linux联盟
sleep1stc2Linux联盟
fi
#-------------------------------tc2Linux联盟
elif["$date2"-lt5]&&["$date2"-gt3]tc2Linux联盟
thentc2Linux联盟
whilereadclrall;dotc2Linux联盟
clr_conns$clralltc2Linux联盟
done</tmp/tmp111.txttc2Linux联盟
echo"clrat$date">>/tmp/killip/tmp.log.txttc2Linux联盟
fi
#####################################tc2Linux联盟
##-------------------makesystemlog------------------------##tc2Linux联盟
#####################################tc2Linux联盟
if[!-e/tmp/killip/tmp.log.txt];thentc2Linux联盟
mkdir/tmp/killiptc2Linux联盟
touch/tmp/killip/tmp.log.txttc2Linux联盟
fitc2Linux联盟
echo"$wc$date$cpu$cpu2$wcblackip3 $wcblackip2 $wcblackip1">>/tmp/killip/tmp.log.txt