package main import ( "fmt" "net" ) func main() { ip1 := net.ParseIP("192.0.2.1") ip2 := net.ParseIP("192.0.2.1") if ip1.Equal(ip2) { fmt.Println("IP addresses are equal") } else { fmt.Println("IP addresses are not equal") } }
package main import ( "fmt" "net" ) func main() { ip1 := net.ParseIP("2001:db8:85a3::8a2e:370:7334") ip2 := net.ParseIP("2001:db8:85a3::8a2e:370:7334") if ip1.Equal(ip2) { fmt.Println("IP addresses are equal") } else { fmt.Println("IP addresses are not equal") } }In this example, we create two IPv6 addresses using net.ParseIP() and compare them using IP.Equal(). Since both IP addresses are the same, the program prints "IP addresses are equal". These examples are part of the net package library in Go.