• --:)欢迎访问锋网源码(:--
  • 首页
  • RSS订阅
  • 常用软件
  • 网页模板
  • 网站运作
  • 锋网学院
  • 繁體中文

  • 学院首页
  • 新闻资讯
  • 网站运营
  • 网站开发
  • 美工设计
  • 数据库类
  • 服务器类
  • 网络应用
  • 操作系统
  • 软件教学
编程开发   认证考试   网络安全   文章搜索: 高级搜索
会员登录/控制面版 您的位置: 学院首页 >> 编程开发 >> shell教程 >> 文章内容
 

精彩推荐

 
 

本类推荐文章

 
 

本类阅读排行

  • shell编程例子--一个简单的目..
  • Shell介绍
  • Shell初学者的入门知识
  • shell编程例子--一个.login例..
  • Linux程式设计-11.ShellScri..
  • Shell编程
  • 从ifconfig中得到IP地址
  • Linux程式设计-11.ShellScri..
  • Linux程式设计-11.ShellScri..
  • shell要如何分类呢?
  • Linux程式设计-11.ShellScri..
  • Shell递归程序设计-目录列表
  • 两个很详细的shell实例
  • Shell介绍
  • Linux程式设计-11.ShellScri..
  • Bash中的变量
  • 批量添加用户
  • Linux程式设计-11.ShellScri..
  • Linux程式设计-11.ShellScri..
  • 我要如何将csh的stdout与std..
 
 

利用ip_conntrack表实现封ip的shell脚本,并有简单的web发布

  • 日期:2007-10-20     人气:     出处:     作者:
  • 字体大小:
  • 小
  • 中
  • 大

#!/bin/bash
#
#---------------------------------------------------------------------------------------
#Scripname:killip,baseonip_conntrack,writebywwy.
#---------------------------------------------------------------------------------------

cpu=`sar-u11|awk'{print$7}'|tail-1`
#
while["`pidofsleep`"];do
echo"sheisrunning,sorry"
exit1
done
if[!"`lsmod|grepip_conntrack`"];then
modprobeip_conntrack
fi

####################################
##----------------------functions-----------------------------##
####################################

functionmake_clr{
whilereadclr33;do
cat/tmp/tmp111.txt|grep$clr33>>/tmp/tmp33-3-clr.txt
done</tmp/tmp33-3.txt
whilereadclr22;do
cat/tmp/tmp111.txt|grep$clr22>>/tmp/tmp33-2-clr.txt
done</tmp/tmp33-2.txt
whilereadclr11;do
cat/tmp/tmp111.txt|grep$clr11>>/tmp/tmp33-1-clr.txt
done</tmp/tmp33-1.txt
}
functionclr_conns{
S_IP=$1
D_IP=$2
S_PORT=$3
D_PORT=$4
hping2$D_IP-R-s$S_PORT-p$D_PORT-a$S_IP-k-c1>/dev/null2>/dev/null&
}
functionkill(){
SLEEP_TIME=$1
CLR_LIST=$2
BLACK_LIST=$3
whilereadblackip;do
iptables-IFORWARD2-ieth0-s$blackip/32-jDROP
done<$BLACK_LIST
sleep$SLEEP_TIME
#-----------------------------------#
whilereadclr3;do
clr_conns$clr3
done<$CLR_LIST
#-----------------------------------#
sleep1
whilereadreblackip;do
iptables-DFORWARD-ieth0-s$reblackip/32-jDROP
done<$BLACK_LIST

}
#####################################
##---------------Tomakea"blacklist"----------------------##
#####################################

echo>/tmp/tmp11.txt
echo>/tmp/tmp111.txt
echo>/tmp/ip_conntrack.tmp
echo>/tmp/tmp33-3-clr.txt
echo>/tmp/tmp33-2-clr.txt
echo>/tmp/tmp33-1-clr.txt
echo>/tmp/tmp22-3.txt
echo>/tmp/tmp22-2.txt
echo>/tmp/tmp22-1.txt
echo>/tmp/tmp33-3.txt
echo>/tmp/tmp33-2.txt
echo>/tmp/tmp33-1.txt
if[!-e/var/www/html/wwy/index.html];then
mkdir/var/www/html/wwy/
mkdir/var/www/html/wwy/all
mkdir/var/www/html/wwy/drop
5B
touch/var/www/html/wwy/index.html
fi
#----------------------------------------------------------------------------#
echo-e"cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmp......\c"
cp/proc/net/ip_conntrack/tmp/ip_conntrack.tmp
echo-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.txt
awk'{$1}{if($1>=50&&$1<100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-2.txt
awk'{$1}{if($1>=100)print$2}'/tmp/tmp11.txt>/tmp/tmp22-3.txt
cut-c1-15/tmp/tmp22-1.txt>/tmp/tmp33-1.txt
cut-c1-15/tmp/tmp22-2.txt>/tmp/tmp33-2.txt
cut-c1-15/tmp/tmp22-3.txt>/tmp/tmp33-3.txt
wcblackip1=`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.html
echo"<p>youconnect<b>\">100\"</b>,youipwillbekilledin<b>30min</b>.</p>">>/var/www/html/wwy/drop/index.html
echo"<p>youconnect<b>\"50-100\"</b>,youipwillbekilledin<b>15min</b>.</p>">>/var/www/html/wwy/drop/index.html
echo"<p>youconnect<b>\"30-50\"</b>,youipwillbekilledin<b>10min</b>.</p>">>/var/www/html/wwy/drop/index.html
echo"<hrcolor=\"#ff8000\">">>/var/www/html/wwy/drop/index.html
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.html
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.html
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.html
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.html
echo"<p><b>Youcan\"ctrl F\"tofindyourip'sconnects.(total$wcIPsat$date)</b></p>">/var/www/html/wwy/all/index.html
echo"<p><ahref=../drop><--back</a></p>">>/var/www/html/wwy/all/index.html
cat/tmp/tmp11.txt|sort-nr|awk'{print"<p>"$1"\t",$2"\t""</p>"}'>>/var/www/html/wwy/all/index.html

#####################################
##-----------------UseiptablestoDROP---------------------##
#####################################

make_clr
if[-s/tmp/tmp33-3.txt];then
kill30m/tmp/tmp33-3-clr.txt/tmp/tmp33-3.txt&
sleep1s
fi
if[-s/tmp/tmp33-2.txt];then
kill15m/tmp/tmp33-2-clr.txt/tmp/tmp33-2.txt&
sleep1s
fi
if[-s/tmp/tmp33-1.txt];then
kill10m/tmp/tmp33-1-clr.txt/tmp/tmp33-1.txt&
sleep1s
fi

#-------------------------------
elif["$date2"-lt5]&&["$date2"-gt3]
then
whilereadclrall;do
clr_conns$clrall
done</tmp/tmp111.txt
echo"clrat$date">>/tmp/killip/tmp.log.txt
fi

#####################################
##-------------------makesystemlog------------------------##
#####################################
if[!-e/tmp/killip/tmp.log.txt];then
mkdir/tmp/killip
touch/tmp/killip/tmp.log.txt
fi
echo"$wc$date$cpu$cpu2$wcblackip3 $wcblackip2 $wcblackip1">>/tmp/killip/tmp.log.txt

相关文章
  • QQ帮你突破网吧硬盘访问限制
  • 局域网内盗用IP的安全问题
  • 邮件安全攻略:只要糖衣不要炮弹
  • 手机病毒的分类及其防范措施
  • 如何防止黒客远程盗取QQ密码
  • 始料未及,谁在控制电脑重新启动
  • 网络常见木马的手工清除方法
  • 魔高一尺 道高一丈
  • 防火墙日志记录让蠕虫病毒无处可逃
  • 提防他人动用电脑另有妙招
相关软件

  • 网友评论:
  • 查看所有评论
  • 我要发表评论
 

关于本站 | 广告联系 | 版权声明 | 网站地图 | 加入收藏 | 帮助中心 |

Copyright © 2006-2007 fwvv.net  程序支持:木翼  皖ICP备06004916号