import ( "net" "fmt" ) func main() { ip := net.IP{192, 168, 0, 0} mask := net.CIDRMask(24, 32) network := net.IPNet{IP: ip, Mask: mask} fmt.Println(network.String()) }
192.168.0.0/24
import ( "net" "fmt" ) func main() { _, ipnet, err := net.ParseCIDR("10.10.0.0/16") if err != nil { fmt.Println(err) return } fmt.Println(ipnet.String()) }
10.10.0.0/16This example parses a CIDR notation string to create an IPNet object and then prints its string representation. Package Library: The IPNet type is part of the net package in Go.