This method is used to passively count the number of IP connections. iptables is used to block IP addresses with a large number of connections. For more information, see iptables to limit the number of ip connections to prevent CC attacks. The Shell script is as follows :#! /Bin/bash # Createdbyhttp: // www. service-labs.comnum = 100 # Upper Limit list = 'netstat-an | grep ^ tcp. *: This method is used to passively count the number of IP connections. You can use iptables to block IP addresses with a large number of connections. For more information, see iptables to limit the number of ip connections to prevent CC attacks.
The Shell script is as follows:
The Code is as follows :#! /Bin/bash
# Created by http://www.service-labs.com
Num = 100 # Upper Limit
List = 'netstat-an | grep ^ tcp. *: 80 | egrep-v 'Listen | 127.0.0.1 '| awk-F "[] + | [:] '{print $6}' | sort | uniq-c | sort-rn | awk '{if ($1> $ num) {print $2 }}''
For I in $ list
Do
Iptables-I input-s $ I? Dport 80-j DROP
Done
Add a crontab to schedule a task:
The Code is as follows:
Crontab-e
*/5 * sh/path/file. sh # Run the command once every 5 minutes.