code.fastix.org

Dateiansicht:

Datei:Projekte -> Apache,mod_evasive,iptables:Helfer-Skripte zum (zeitweisen) Blockieren von IP-Adressen -> fwblock
md5:5ac5a0482aa59acaa12ac361160315ca
sha1:db771211448a51d16f71beb291894a587ec3adef
Download-Link:Download
  1. #!/usr/bin/sudo /bin/bash
  2.  
  3. ## safety instructions:  ##
  4. ##   chown root:root     ##
  5. ##   chmod 0755          ##
  6.  
  7. errMsgWholeNet='Sorry! It is to dangerous to block the whole net. This is also not allowed. This is really an error.';
  8.  
  9.  
  10. if [ -z "$1" ]; then
  11.         echo 'Kein Parameter angegeben.';
  12.         exit 1;
  13.  
  14. else
  15.         ip=$(echo -n "${1}" | tr -cd '0123456789./');
  16.  
  17.         network=$(echo "${ip}" | cut -s -d '/' -f2);
  18.         if [ -n "${network}" ]; then
  19.                 if [ '0.0.0.0' = "${network}" ]; then
  20.                         echo "${errMsgWholeNet}";
  21.                         exit 4;
  22.                 fi
  23.                 network=$((${network}));
  24.                 if [ 0 -eq ${network} ]; then
  25.                         echo "${errMsgWholeNet}";
  26.                         exit 4;
  27.                 fi
  28.         fi
  29.  
  30.         if iptables -A INPUT -s "${ip}" -j DROP; then
  31.                 fwlist | tee /tmp/fwlist.txt | grep "${ip}";
  32.                 exit 0;
  33.         else
  34.                 exit 2;
  35.         fi
  36. fi
  37.