Fixing valid_ipv6 function to better detect all potential cases of ipv6

This commit is contained in:
Eric Renfro 2021-01-31 13:25:15 -05:00
parent 1f12684a81
commit 8fb399ad68
Signed by untrusted user who does not match committer: psi-jack
GPG Key ID: 14977F3A50D9A5BF
1 changed files with 4 additions and 1 deletions

View File

@ -37,8 +37,11 @@ valid_ipv4() {
valid_ipv6() {
local ip=$1
local regex='^([[:xdigit:]]{0,4}:){1,7}[[:xdigit:]]{0,4}$'
#local regex='^$|^[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}$'
if [[ $ip =~ ^$|^[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}$ ]]; then
#if [[ $ip =~ ^$|^[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}:[0-9a-fA-F]{1,4}$ ]]; then
if [[ $ip =~ $regex ]]; then
return 0
else
return 1