Anti-DDoS script CC attack

Source: Internet
Author: User

#! /Bin/sh

# Auther rum

# Date 20140716

CC ()

{

[-F ignore. IP. LIST] | echo "127.0.0.1"> ignore. IP. List

Netstat-NTU | awk '{print $5}' | cut-D:-F4 | sort | uniq-c | sort-Nr> bad_ip_list

While read line; do

Curr_line_conn = $ (echo $ Line | cut-d ""-F1)

Curr_line_ip =$ (echo $ Line | cut-d ""-F2)

Iptables-l-N | grep-I $ curr_line_ip>/dev/null

If [$? = 0]; then

Break

Else

If [$ curr_line_conn-lt 100]; then

Break

Else

Ignore_ban = 'grep-c "$ curr_line_ip" ignore. IP. list'>/dev/null

If [$ ignore_ban-ge 1]; then

Continue

Else

Iptables-I input-S $ curr_line_ip-J Drop>/dev/null

Fi

Fi

Fi

Done <bad_ip_list

}

While true; do

CC

Sleep 1

Done



1 ignore. IP. List can be added to the White List

2 $ curr_line_conn-lt 100 this 100 is defined as per your needs. Here, 100 concurrent connections are written and rejected by default.


Finally, the script runs cyclically in the background.

This article is from the blog "Believe It Or Not", please be sure to keep this source http://312461613.blog.51cto.com/965442/1439774

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.