summarylogtreecommitdiffstats
path: root/ip64tables
blob: 7b1639de53359a4a0ae5dac5fa9c2311d422ed88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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