Created
May 1, 2016 20:23
-
-
Save makeittotop/e134b7b4661c010578b46c696ef20565 to your computer and use it in GitHub Desktop.
Android created Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
counter=0 | |
IFS=$'\n' | |
for input in $(netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | sed -e 's/^[ \t]*//' | grep -v [a-z]) | |
do | |
connections=$(echo $input | cut -d " " -f1) | |
source=$(echo $input | cut -d " " -f2) | |
if [ $connections -gt 50 ] | |
then | |
iptables -A INPUT -s $source -j DROP | |
echo "$source added to iptables on $(date)" >> /root/ban.txt | |
counter=$[ counter + 1 ] | |
fi | |
done | |
if [ $counter -gt 0 ] | |
then | |
service iptables save | |
service httpd restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment