ip := net.ParseIP("192.168.0.1") subnet := &net.IPNet{ IP: net.ParseIP("192.168.0.0"), Mask: net.IPv4Mask(255, 255, 255, 0), } if subnet.Contains(ip) { fmt.Println("IP address is within the subnet") } else { fmt.Println("IP address is outside the subnet") }
subnet := &net.IPNet{ IP: net.ParseIP("192.168.0.0"), Mask: net.IPv4Mask(255, 255, 255, 0), } network := subnet.Network() broadcast := subnet.Broadcast() fmt.Printf("Network address: %s\n", network.String()) fmt.Printf("Broadcast address: %s\n", broadcast.String())This package is part of the standard Go library.