2023-05-30 14:34:34 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-08-22 13:48:43 +00:00
|
|
|
// IsIPv4 validates if string is a valid IPV4 address
|
2023-05-30 14:34:34 +00:00
|
|
|
func IsIPv4(str string) bool {
|
2023-08-22 13:48:43 +00:00
|
|
|
ip := net.ParseIP(str).To4()
|
|
|
|
return ip != nil
|
2023-05-30 14:34:34 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 13:48:43 +00:00
|
|
|
// IsIPv6 validates if string is a valid IPV6 address
|
2023-05-30 14:34:34 +00:00
|
|
|
func IsIPv6(str string) bool {
|
|
|
|
ip := net.ParseIP(str)
|
|
|
|
return ip != nil && strings.Contains(str, ":")
|
|
|
|
}
|