#! /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