linux防止爬虫脚本,屏蔽爬虫ip抓取。自动执行没小时一次

# 每小时执行一次上面的脚本crontable  0 */1 * * * sh /script/block_ip.sh

#功能 每小时限制一下ip。每小时访问大于1000次的ip被封锁。

#!/bin/sh

lastdate=`/bin/date -d last-minute +%Y%m%d`

IP_LIST_FILE=/script/deny.txt

/bin/cat /opt/web_logs/cctv_access_$lastdate.log | grep `date -d last-minute +%Y:%H`|awk '{print $1}' |sort |uniq -c|sort -nr|head -n 10 |awk '{if($1>1000) {print $2} }' >$IP_LIST_FILE

IPTABLES_BIN=/sbin/iptables

BAD_IP_ADDR_LIST=$(grep -Ev "^#" $IP_LIST_FILE)

#######ACCEPT wanghailou access 202.108.16.65/27  202.108.17.0/24  220.181.168.0/24#############

for i in $BAD_IP_ADDR_LIST

do

echo -n "Blocking $i ...";

$IPTABLES_BIN -D INPUT -s $i -j DROP

$IPTABLES_BIN -D OUTPUT -d $i -j DROP

$IPTABLES_BIN -A INPUT -s $i -j DROP

$IPTABLES_BIN -A OUTPUT -d $i -j DROP

echo "DONE.";

done

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值