From c15b03264cf1e1f81f56517ad712dab04d5311f5 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 29 Jul 2017 14:07:07 +0200 Subject: [PATCH] Add support for IPv6. --- ip64tables | 29 +++++++++++++++++++++++++++++ iptables_manage_chain.sh | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 ip64tables diff --git a/ip64tables b/ip64tables new file mode 100755 index 0000000..7b1639d --- /dev/null +++ b/ip64tables @@ -0,0 +1,29 @@ +#!/bin/bash +# iptables/ip6tables switch +LINE=$* + +RESULT=`echo $LINE | egrep " ([0-9]{1,3}\.){3}[0-9]{1,3}" | wc -l` +RESULT6=`echo $LINE | egrep "(::[A-Fa-f0-9])|((:[A-Fa-f0-9]{1,4}){2,})" | wc -l ` + +if [ $RESULT -eq "1" ]; then + # IPv4 + iptables $LINE + ERRCODE=$? + +elif [ $RESULT6 -eq "1" ]; then + # IPv6 + ip6tables $LINE + ERRCODE=$? + +else + # IPv4 + IPv6 + iptables $LINE + ERRCODE=$? + ip6tables $LINE + if [ $? -ge "1" ]; then + ERRCODE=$? + fi + +fi + +exit $ERRCODE diff --git a/iptables_manage_chain.sh b/iptables_manage_chain.sh index e66a410..94cf7c4 100755 --- a/iptables_manage_chain.sh +++ b/iptables_manage_chain.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -ipt=`which /sbin/iptables` +working_dir="$(dirname $(realpath $0))" +ipt="${working_dir}/ip64tables" default_iptables_chain=custom-`hostname -s`