SHARE
TWEET

Untitled

a guest Nov 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. cd "${0%/*}" #the directory containing the script
  3. cd ..
  4. MYDIR=$(pwd)
  5. IP=$1 #input from user
  6.  
  7. TIMESTAMP=$(date +%s)
  8.  
  9. banning() {
  10.     if [[ ($(grep -c $IP $MYDIR/miniban.whitelist) -eq 0) ]]; then
  11.             echo $IP,$TIMESTAMP  >> $MYDIR/miniban.db
  12.         sudo iptables -A INPUT -p tcp -s $IP --dport 22 -j REJECT
  13. #             sed -i /$IP/d $MYDIR/kickcount.db
  14.             echo "$IP har blitt blokkert fra SSH-authentication"
  15.     else
  16.         echo "$IP er i whitelisten"
  17. fi
  18. }
  19.  
  20.  
  21.  
  22. #IPv4
  23. if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
  24.     banning        
  25. #   sudo iptables -A INPUT -p tcp -s $IP --dport 22 -j REJECT
  26.    
  27.  
  28. #IPv6
  29. elif [[ $IP =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then
  30.         banning
  31. #   sudo ip6tables -A INPUT -p tcp -s $IP --dport 22 -j REJECT
  32. else
  33.     echo "Skriv inn gyldig IP"
  34. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top