Created
July 7, 2015 07:18
-
-
Save kimitoboku/27b5d2838a2ebf1dce4f to your computer and use it in GitHub Desktop.
block.sh
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/sh | |
sudo iptables -F | |
sudo iptables -P INPUT ACCEPT | |
sudo iptables -P FORWARD ACCEPT | |
sudo iptables -P OUTPUT ACCEPT | |
sudo /etc/init.d/apache2 restart | |
sudo sysctl -w vm.drop_caches=3 | |
vmstat 1 700 > status.log & | |
sudo tail -f /var/log/apache2/p3/access.log | awk '{ | |
d = sprintf("%s-%s",$1,$4) | |
if($1 ~ /::1/) | |
{ | |
}else if(list[$1]=="done"){ | |
}else if(!(d in data)){ | |
data[d] = 0; | |
}else if(data[d] == 0){ | |
c = sprintf("sudo iptables -I INPUT -s %s -j DROP", $1); | |
print c; | |
system(c); | |
close(c); | |
list[$1]="done"; | |
}else{ | |
data[d]++; | |
} | |
}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment