Results 1 to 2 of 2

Thread: block_ip.sh and Debian

  1. #1
    Join Date
    Feb 2005
    Location
    The Netherlands
    Posts
    313

    block_ip.sh and Debian

    Does anyone over here have any experience with the DA supplied block_ip.sh and Debian as outlined on this DirectAdmin help page:

    https://help.directadmin.com/item.php?id=380

  2. #2
    Join Date
    Aug 2017
    Posts
    2

    My sample file I'm using

    Code:
    #!/bin/sh
    
    BF=/root/blocked_ips.txt
    EF=/root/exempt_ips.txt
    
    curriptables()
    {
            echo "<br><br><textarea cols=160 rows=60>";
            /sbin/iptables -nL
            echo "</textarea>";
    }
    
    COUNT=`grep -c "^${ip}\$" $EF`;
    if [ "$COUNT" -ne 0 ]; then
            echo "$ip in the exempt list ($EF). Not blocking.";
            curriptables
            exit 2;
    fi
    
    COUNT=`grep -c $ip /etc/network/iptables.save`;
    if [ "$COUNT" -ne 0 ]; then
            echo "$ip already exists in iptables ($COUNT). Not blocking.";
            curriptables
            exit 2;
    fi
    
    echo "Adding $ip to iptables...<br>";
    /sbin/iptables -I INPUT -s $ip -j DROP
    /sbin/iptables-save > /etc/network/iptables.save
    echo "$ip=dateblocked=`date +%s`" >> $BF;
    
    echo "<br><br>Result:";
    curriptables
    exit 0;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •