Add a function to tell whether an IP is a v4 or v6 one

This commit is contained in:
Tristan PILAT 2020-11-18 17:49:35 +01:00
parent 520b8893f0
commit 519a0f9c60
1 changed files with 20 additions and 0 deletions

View File

@ -64,6 +64,26 @@ for i in /proc/sys/net/ipv4/conf/*/log_martians; do
echo 1 > $i
done
############
## FUNCTIONS
############
# Determine IP type
ip_type() {
v4_ips=""
v6_ips=""
for ip in $(echo $1 | sed 's/ /, /g'); do
if [ "$ip" != "${ip#*[0-9].[0-9]}" ]; then
v4_ips="$v4_ips$ip "
elif [ "$ip" != "${ip#*:[0-9a-fA-F]}" ]; then
v6_ips="$v6_ips$ip "
else
echo "Unrecognized IP format '$ip'"
exit 1
fi
done
}
#########################
## NFTables configuration
#########################