import "net" ip := net.ParseIP("192.168.0.1") mask := net.CIDRMask(24, 32) // equivalent to 255.255.255.0 network := &net.IPNet{ IP: ip, Mask: mask, }
import "net" ip := net.ParseIP("192.168.0.10") network := &net.IPNet{ IP: net.ParseIP("192.168.0.0"), Mask: net.CIDRMask(24, 32), // equivalent to 255.255.255.0 } if network.Contains(ip) { fmt.Println("IP address is within the network") }
import "net" network := &net.IPNet{ IP: net.ParseIP("192.168.0.0"), Mask: net.CIDRMask(24, 32), // equivalent to 255.255.255.0 } networkAddress := network.IP broadcastAddress := make(net.IP, len(network.IP)) for i := range broadcastAddress { broadcastAddress[i] = network.IP[i] | ^network.Mask[i] }In these examples, we can see that the IPNet Mask package is used to create and manipulate IP network addresses, masks, and subnets. Additionally, it is part of the standard Go "net" package.