#!/bin/bash##---------------------------------------------------------------------------------------#Scripname:killip,baseonip_conntrack,writebywwy.#---------------------------------------------------------------------------------------
cpu=`sar-u11|awk'{print$7}'|tail-1`#while["`pidofsleep`"];doecho"sheisrunning,sorry"exit1doneif[!"`lsmod|grepip_conntrack`"];thenmodprobeip_conntrackfi
######################################----------------------functions-----------------------------######################################
functionmake_clr{whilereadclr33;docat/tmp/tmp111.txt|grep$clr33>>/tmp/tmp33-3-clr.txtdone</tmp/tmp33-3.txtwhilereadclr22;docat/tmp/tmp111.txt|grep$clr22>>/tmp/tmp33-2-clr.txtdone</tmp/tmp33-2.txtwhilereadclr11;docat/tmp/tmp111.txt|grep$clr11>>/tmp/tmp33-1-clr.txtdone</tmp/tmp33-1.txt}functionclr_conns{S_IP=$1D_IP=$2S_PORT=$3D_PORT=$4hping2$D_IP-R-s$S_PORT-p$D_PORT-a$S_IP-k-c1>/dev/null2>/dev/null&}functionkill(){SLEEP_TIME=$1CLR_LIST=$2BLACK_LIST=$3whilereadblackip;doiptables-IFORWARD2-ieth0-s$blackip/32-jDROPdone<$BLACK_LISTsleep$SLEEP_TIME#-----------------------------------#whilereadclr3;doclr_conns$clr3done<$CLR_LIST#-----------------------------------#sleep1whilereadreblackip;doiptables-DFORWARD-ieth0-s$reblackip/32-jDROPdone<$BLACK_LIST
}#######################################---------------Tomakea"blacklist"----------------------#######################################
echo>/tmp/tmp11.txtecho>/tmp/tmp111.txtecho>/tmp/ip_conntrack.tmpecho>/tmp/tmp33-3-clr.txtecho>/tmp/tmp33-2-clr.txtecho>/tmp/tmp33-1-clr.txtecho>/tmp/tmp22-3.txtecho>/tmp/tmp22-2.txtecho>/tmp/tmp22-1.txtecho>/tmp/tmp33-3.txtecho>/tmp/tmp33-2.txtecho>/tmp/tmp33-1.txtif[!-e/var/www/html/wwy/index.html];thenmkdir/var/www/html/wwy/mkdir/var/www/html/wwy/allmkdir/var/www/html/wwy/drop5Btouch/var/www/html/wwy/index.htmlfi#----------------------------------------------------------------------------#echo-e"cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmp......\c"cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmpecho-e"done!\n"sleep1#----------------------------------------------------------------------------#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`date=`date' m/dH:M'`cpu2=`sar-u11|awk'{print$7}'|tail-1`date2=`date' H'`#----------------------------------------------------------------------------#sleep1#----------------------------------------------------------------------------##if["$wc"-gt2500]&&["$date2"-gt10]if["$wc"-ge0]then#------------------------------awk'{$1}{if($1>30&&$1<50)print$2}'/tmp/tmp11.txt>/tmp/tmp22-1.txtawk'{$1}{if($1>=50&&$1<100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-2.txtawk'{$1}{if($1>=100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-3.txtcut-c1-15/tmp/tmp22-1.txt>/tmp/tmp33-1.txtcut-c1-15/tmp/tmp22-2.txt>/tmp/tmp33-2.txtcut-c1-15/tmp/tmp22-3.txt>/tmp/tmp33-3.txtwcblackip1=`cat/tmp/tmp33-1.txt|wc-l`wcblackip2=`cat/tmp/tmp33-2.txt|wc-l`wcblackip3=`cat/tmp/tmp33-3.txt|wc-l`
########################################----------------Tomakeaindex.html-----------------------########################################
echo"<b>IfthetotalIPs>2500<fontcolor=\"#ff0000\">(total$wcat$date)</font>ANDif:</b>">/var/www/html/wwy/drop/index.htmlecho"<p>youconnect<b>\">100\"</b>,youipwillbekilledin<b>30min</b>.</p>">>/var/www/html/wwy/drop/index.htmlecho"<p>youconnect<b>\"50-100\"</b>,youipwillbekilledin<b>15min</b>.</p>">>/var/www/html/wwy/drop/index.htmlecho"<p>youconnect<b>\"30-50\"</b>,youipwillbekilledin<b>10min</b>.</p>">>/var/www/html/wwy/drop/index.htmlecho"<hrcolor=\"#ff8000\">">>/var/www/html/wwy/drop/index.htmlecho"<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.htmlawk'{$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.htmlawk'{$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.htmlawk'{$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.htmlecho"<p><b>Youcan\"ctrl F\"tofindyourip'sconnects.(total$wcIPsat$date)</b></p>">/var/www/html/wwy/all/index.htmlecho"<p><ahref=../drop><--back</a></p>">>/var/www/html/wwy/all/index.htmlcat/tmp/tmp11.txt|sort-nr|awk'{print"<p>"$1"\t",$2"\t""</p>"}'>>/var/www/html/wwy/all/index.html
#######################################-----------------UseiptablestoDROP---------------------#######################################
make_clrif[-s/tmp/tmp33-3.txt];thenkill30m/tmp/tmp33-3-clr.txt/tmp/tmp33-3.txt&sleep1sfiif[-s/tmp/tmp33-2.txt];thenkill15m/tmp/tmp33-2-clr.txt/tmp/tmp33-2.txt&sleep1sfiif[-s/tmp/tmp33-1.txt];thenkill10m/tmp/tmp33-1-clr.txt/tmp/tmp33-1.txt&sleep1sfi
#-------------------------------elif["$date2"-lt5]&&["$date2"-gt3]thenwhilereadclrall;doclr_conns$clralldone</tmp/tmp111.txtecho"clrat$date">>/tmp/killip/tmp.log.txtfi
#######################################-------------------makesystemlog------------------------#######################################if[!-e/tmp/killip/tmp.log.txt];thenmkdir/tmp/killiptouch/tmp/killip/tmp.log.txtfiecho"$wc$date$cpu$cpu2$wcblackip3 $wcblackip2 $wcblackip1">>/tmp/killip/tmp.log.txt