package main import ( "fmt" "net" ) func main() { ipAddr, err := net.ParseIP("192.168.0.1") if err != nil { fmt.Println("Invalid IP Address") } else { fmt.Println("IP Address:", ipAddr) } }
package main import ( "fmt" "net" ) func main() { ipAddr := "10.0.0.256" if net.ParseIP(ipAddr) == nil { fmt.Printf("%s is an invalid IP address\n", ipAddr) } else { fmt.Printf("%s is a valid IP address\n", ipAddr) } }This code example checks if the IP address "10.0.0.256" is a valid IP address or not using the `net.ParseIP()` function to convert the string into an `net.IP` type. If the result is nil, then the address is invalid. The `net` package is the library corresponding to the go net IP String package.