Skip to content

Commit

Permalink
Add combinatory fuction for validate ipv4 & ipv6
Browse files Browse the repository at this point in the history
Signed-off-by: Louis <covert8@users.noreply.github.com>
  • Loading branch information
covert8 committed Jul 14, 2023
1 parent 00b8f57 commit c6ab2ea
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ validate_port() {
fi
}

########################
# Validate if the provided argument is a valid IPv4 or IPv6 address
# Arguments:
# $1 - IP to validate
# Returns:
# Boolean
#########################
validate_ip() {
local ip="${1:?ip is missing}"
local stat=1

validate_ipv4 "$ip"
if [[ $? -eq 0 ]]; then
stat=0
else
validate_ipv6 "$ip"
stat=$?
fi

return $stat
}

########################
# Validate if the provided argument is a valid IPv4 address
# Arguments:
Expand All @@ -206,6 +228,7 @@ validate_ipv4() {
fi
return $stat
}

########################
# Validate if the provided argument is a valid IPv6 address
# Arguments:
Expand All @@ -227,6 +250,7 @@ validate_ipv6() {

echo $stat
}

########################
# Validate a string format
# Arguments:
Expand Down

0 comments on commit c6ab2ea

Please sign in to comment.