Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created July 7, 2015 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimitoboku/27b5d2838a2ebf1dce4f to your computer and use it in GitHub Desktop.
Save kimitoboku/27b5d2838a2ebf1dce4f to your computer and use it in GitHub Desktop.
block.sh
#! /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