import ( "net" ) func main() { ipnet, err := net.ParseCIDR("192.168.0.0/16") if err != nil { // handle error } // ipnet now contains the network address and subnet mask }
import ( "fmt" "net" ) func main() { ipnet := &net.IPNet{ IP: net.ParseIP("192.168.0.0"), Mask: net.CIDRMask(16, 32), } ip := net.ParseIP("192.168.1.1") if ipnet.Contains(ip) { fmt.Println("The IP address is in the network") } else { fmt.Println("The IP address is not in the network") } }In this example, we create an `IPNet` object that represents the IP network `192.168.0.0/16`. Then, we parse an IP address, `192.168.1.1`, and use the `Contains()` method to check if it is in the network. The package library for both these examples is the `net` package in Go. It provides functionality for working with network addresses and connections.