Skip to content

Instantly share code, notes, and snippets.

@makeittotop
Created May 1, 2016 20:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save makeittotop/e134b7b4661c010578b46c696ef20565 to your computer and use it in GitHub Desktop.
Save makeittotop/e134b7b4661c010578b46c696ef20565 to your computer and use it in GitHub Desktop.
Android created Gist
#!/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