Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. deny='/etc/hosts.deny'
  4. tmpfil='/tmp/fail.txt'
  5.  
  6. isdup() {
  7. while read ln
  8. do
  9. if echo "$ln" | grep "$1"
  10. then
  11. return 0
  12. fi
  13. done < "$deny"
  14. return 1
  15. }
  16.  
  17. while true
  18. do
  19. if tail /var/log/auth.log | grep failures | tee "$tmpfil"
  20. then
  21. ip=$(cat "$tmpfil" | cut -d ' ' -f 17 | grep 'rhost=' | sed s/rhost=//g)
  22. if isdup "$ip"
  23. then
  24. echo "ring polisen banditer på $ip som redan borde vara blockerad"
  25. else
  26. echo "ring polisen banditer på $ip"
  27. echo "ALL: $ip" >> "$deny"
  28. fi
  29. fi
  30. sleep 2m
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement