Advertisement
Guest User

Ban IP:Port from .txt file using crontab

a guest
Feb 4th, 2013
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.16 KB | None | 0 0
  1. #!/bin/sh
  2. # By Anthony Smith - InceptionHosting.com - 2013
  3. # This script bans IPs with specific Ports that are added to a .txt file
  4. # This script should be called every minute as a cronjob/from crontab
  5.  
  6. # build list from user input /var/www/ban.ban-list.txt should be the one your game admis update
  7. # change the path and file name if required
  8.  
  9. cat /var/www/ipban/ban-list.txt | awk '{print $1}' > /ban/banip.txt
  10.  
  11. # loop through list and add to iptables
  12. # this will also add each ip you block to /ban/perm-ban.txt
  13. # you can run 'cp /ban/perm-ban.txt /ban/banip.txt' after a reboot and run this script
  14. # this will re ban any previously banned ip's if you are not saving your iptables config
  15.  
  16. while read blist
  17. do
  18. /sbin/iptables -A INPUT -s $blist -p udp -m udp --dport 28960:28965 -j DROP && sleep 2
  19. echo $blist has been added to your iptables
  20. echo $blist >> /ban/perm-ban.txt
  21. done < /ban/banip.txt
  22.  
  23. # tidy up files
  24. # on the next few lines update the path after touch to be the same as the first line
  25. # example /var/www/ban/ban-list.txt
  26.  
  27. rm /ban/banip.txt
  28. rm /var/www/ipban/ban-list.txt
  29. touch /var/www/ipban/ban-list.txt
  30. chmod 777 /var/www/ipban/ban-list.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement