Source IP address blocking script

Source: Internet
Author: User

The script to block the source IP address when the website is subject to abnormal connections from a large number of hosts.
 
#! /Bin/bash
Touch all
For I in 'seq 1 100 '// controls the loop of the script
Do
Sleep 1 time control
Ip = 'Tail-30/var/log/. log | grep HTTP/1.1 | awk '{print $1}' | sort-n | uniq '// extract the IP address of the host that is not properly connected from a hypothetical log file, attack features
If [-z "$ ip"]; then // www.2cto.com if there is no such host
Ehco "OK">/dev/null
Else
For m in 'echo $ ip' // traverse if these hosts exist
Do
N = 'grep-l "^ $ m $"/root/all' // check whether the object has been disabled.
If [$? -Eq 1]; then // if it has not been disabled
Echo iptables-a input-s $ m-p tcp-dport 80-j DROP
Echo "iptables-a input-s $ m-p tcp-dport 80-j DROP"
Iptables-a input-s $ m-p tcp-dport 80-j DROP // disable
Echo $ m>/root/all // write to the all file
Fi
Done
Fi
Service iptables save // save iptables rules
Done
Save and exit
 
 
Author http://www.graynight.org /? P = 657

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.