#!/usr/bin/env bash
#
# haxiorIP ver.0.1 alfa beta
#
# Skrypt pomaga w prosty sposob dadawac/usuwac adresy IP,
# ktore chemy zablokowac uzywajac do tego iptables.
#
# by Krzysztof Zmijewski
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.


IPT="/sbin/iptables"
CHAIN=`$IPT -S | grep HIP | wc -l`

function uzycie
{
    echo "Uzycie:"

    echo "$0 addchain      dodaje lancuch HIP do iptables'a"
    echo "$0 delchain      usuwa lancuch HIP z iptables'a"
    echo "$0 addip [IP]    dodaje podany adres IP do lancucha HIP"
    echo "$0 delip [IP]    usuwa podany adres IP z lancucha HIP"
}

function addchain
{
    if [ $CHAIN -eq "0" ]
    then
        echo -n "Tworze lancuch HIP... "
            $IPT -N HIP
            $IPT -I INPUT -j HIP
        echo "OK"
    else
        echo "Lancuch HIP juz istnieje."
    fi
}

function delchain
{
    if [ $CHAIN -eq "0" ]
    then
        echo "Lancuch HIP nie istnieje."
    else
        echo -n "Kasuje lancuch HIP... "
            $IPT -F
            $IPT -X
        echo "OK"
    fi
}

function addip
{
    $IPT -A HIP -s $ip -j DROP
}

function delip
{
    $IPT -D HIP -s $ip -j DROP
}

if [ "$#" -lt 1 ]
then
    uzycie
    exit 1
fi

ip=$2

case "$1" in
    "addchain") addchain ;;
    "delchain") delchain ;;
    "addip") addip ;;
    "delip") delip ;;
    *) uzycie
esac

exit 0


syntax highlighted by Code2HTML, v. 0.9.1