企業網站對於每日訪問量過大的IP進行查封

來源:互聯網
上載者:User

標籤:shell

通過企業網站的記錄檔分析,對於每日訪問量到達一定數量的IP進行查封

指令碼通過傳參的形式,可以對任何日誌進行傳遞分析

ipt函數進行查封,del函數對昨天查封的IP進行解鎖

#!/bin/bash#2017-08-12if [ $# -lt 1 ];then  echo "USAGE:$0 ARG"  exit 1fiipt(){awk ‘{print $1}‘ $1|sort|uniq -c|sort -rn -k1 > /tmp/tmp.logexec</tmp/tmp.logwhile read linedoip=`echo $line|awk ‘{print $2}‘`if [ `echo $line|awk ‘{print $1}‘` -gt 10 -a `iptables -L -n|grep "$ip"|wc -l` -lt 1 ];then  iptables -I INPUT -s $ip -j DROP  echo $ip >>/tmp/ip_$(date +$F).logfidone}del(){  touch /tmp/ip_$(date +$F -d ‘-1day‘).log  exec < /tmp/ip_$(date +$F -d ‘-1day‘).log  while read line  do  if [ `iptables -L -n|grep "$line"|wc -l` -ge 1 ];then  iptables -D INPUT -s $line -j DROP  fi  done}main(){while truedo  ipt $1  sleep 5  deldone}main $*

可以通過加入定時任務方便執行

測試執行的話可以sh <script>.sh XX_2017_xx_xx.log執行,並啟動另一個shell

開啟watch iptables -L -n進行即時查看,如果超過一定數量的IP進入了防火牆drop列表則表明指令碼執行成功。

本文出自 “wxtan” 部落格,請務必保留此出處http://wxtan.blog.51cto.com/13124984/1955818

企業網站對於每日訪問量過大的IP進行查封

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.