f2b_ignore_ip.sh 641 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. ## The point of this script is to add ips to the ignore list
  3. ## So that they don't need to be in my git hosted filters.
  4. ## ./f2b_ignore_ip.sh [add|del] [ip1] [ip2]...
  5. if [ $UID -ne 0 ]; then
  6. echo "Run as root"
  7. exit
  8. fi
  9. if [ -z "$*" ]; then
  10. echo "No augments"
  11. exit
  12. fi
  13. if [ $1 != "del" ] && [ $1 != "add" ]; then
  14. echo "Bad option"
  15. exit
  16. fi
  17. act=$1
  18. shift ## Remove the add/del
  19. ips=$*
  20. jails=$(fail2ban-client status | gawk '/list/ {match($0, /\t(.*)$/, m)}; END {gsub(",","",m[1]);print m[1]}')
  21. for j in $jails; do
  22. for i in $ips;do
  23. fail2ban-client set $j ${act}ignoreip $i
  24. done
  25. done