fail2ban/fail2ban-iptwrp

50 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# This file is part of Fail2Ban.
#
# Fail2Ban 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.
#
# Fail2Ban 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 Fail2Ban; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Author: Paul Jung aka 'Thanat0s'
# IPTable WRaPper
# This script will call iptable or ip6tables6 depending of the ip format
LINE=$@
# try to be simple, keep regexes 'approximatives'
RESULT4=`echo $LINE | egrep -c -e "([0-9]{1,3}\.){3}[0-9]{1,3}"`
RESULT6=`echo $LINE | egrep -c -e "(::[A-Fa-f0-9]{1,4}|(:[A-Fa-f0-9]{1,4}){2,})"`
if [ $RESULT4 -ne "0" ]; then
# action for ipv4
iptables $LINE
ERRCODE=$?
elif [ $RESULT6 -ne "0" ]; then
# action for ipv6
ip6tables $LINE
ERRCODE=$?
else
# action for both iptables if no ip is present
iptables $LINE
ERRCODE=$?
ip6tables $LINE
if [ $? -ge "1" ]; then
ERRCODE=$?
fi
fi
# always report the error
exit $ERRCODE