func IPRangeForCIDR(cidr string) (net.IP, net.IP, error) {
	_, ipNet, err := net.ParseCIDR(cidr)
	if err != nil {
		return net.IP{}, net.IP{}, errors.Trace(err)
	}
	ones, numBits := ipNet.Mask.Size()

	// Special case: CIDR specifies a single address (i.e. a /32 or /128
	// for IPV4 and IPV6 CIDRs accordingly).
	if ones == numBits {
		firstIP := ipNet.IP
		lastIP := make(net.IP, len(firstIP))
		copy(lastIP, firstIP)
		return firstIP, lastIP, nil
	}

	// Calculate number of hosts in network (2^hostBits - 1) or the
	// equivalent (1 << hostBits) - 1.
	hostCount := big.NewInt(1)
	hostCount = hostCount.Lsh(hostCount, uint(numBits-ones))
	hostCount = hostCount.Sub(hostCount, big.NewInt(1))

	// Calculate last IP in range.
	lastIPNum := big.NewInt(0).SetBytes([]byte(ipNet.IP))
	lastIPNum = lastIPNum.Add(lastIPNum, hostCount)

	// Convert last IP into bytes. Since BigInt strips off leading zeroes
	// we need to prepend them again before casting back to net.IP.
	lastIPBytes := lastIPNum.Bytes()
	lastIPBytes = append(make([]byte, len(ipNet.IP)-len(lastIPBytes)), lastIPBytes...)

	return ipNet.IP, net.IP(lastIPBytes), nil
}
// IPRangeForCIDR returns the first and last addresses that correspond to the
// provided CIDR. The first address will always be the network address. The
// returned range also includes the broadcast address. For example, a CIDR of
// 10.0.0.0/24 yields: [10.0.0.0, 10.0.0.255].
IPRangeForCIDR returns the first and last addresses that correspond to the
provided CIDR. The first address will always be the network address. The
returned range also includes the broadcast address.
// IPRangeForCIDR returns the first and last addresses that correspond to the // provided CIDR . The first address will always be the network address . The // returned range also includes the broadcast address . For example a CIDR of // 10 . 0 . 0 . 0 / 24 yields : [ 10 . 0 . 0 . 0 10 . 0 . 0 . 255 ] .
func IPRangeForCIDR(cidr string) (net.IP, net.IP, error) {
	_, ipNet, err := net.ParseCIDR(cidr)
	if err != nil {
		return net.IP{}, net.IP{}, errors.Trace(err)
	}
	ones, numBits := ipNet.Mask.Size()
	if ones == numBits {
		firstIP := ipNet.IP
		lastIP := make(net.IP, len(firstIP))
		copy(lastIP, firstIP)
		return firstIP, lastIP, nil
	}
	hostCount := big.NewInt(1)
	hostCount = hostCount.Lsh(hostCount, uint(numBits-ones))
	hostCount = hostCount.Sub(hostCount, big.NewInt(1))
	lastIPNum := big.NewInt(0).SetBytes([]byte(ipNet.IP))
	lastIPNum = lastIPNum.Add(lastIPNum, hostCount)
	lastIPBytes := lastIPNum.Bytes()
	lastIPBytes = append(make([]byte, len(ipNet.IP)-len(lastIPBytes)), lastIPBytes...)
	return ipNet.IP, net.IP(lastIPBytes), nil
}
func IPRangeForCIDR ( cidr string ) ( net . IP , net . IP , error ) { _ , ipNet , err := net . ParseCIDR ( cidr ) if err != nil { return net . IP { } , net . IP { } , errors . Trace ( err ) } ones , numBits := ipNet . Mask . Size ( ) if ones == numBits { firstIP := ipNet . IP lastIP := make ( net . IP , len ( firstIP ) ) copy ( lastIP , firstIP ) return firstIP , lastIP , nil } hostCount := big . NewInt ( 1 ) hostCount = hostCount . Lsh ( hostCount , uint ( numBits - ones ) ) hostCount = hostCount . Sub ( hostCount , big . NewInt ( 1 ) ) lastIPNum := big . NewInt ( 0 ) . SetBytes ( [ ] byte ( ipNet . IP ) ) lastIPNum = lastIPNum . Add ( lastIPNum , hostCount ) lastIPBytes := lastIPNum . Bytes ( ) lastIPBytes = append ( make ( [ ] byte , len ( ipNet . IP ) - len ( lastIPBytes ) ) , lastIPBytes ... ) return ipNet . IP , net . IP ( lastIPBytes ) , nil }
IPRangeForCIDR returns the first and last addresses that correspond to the
provided CIDR.
IPRangeForCIDR returns the first and last addresses that correspond to the provided CIDR .
// Special case: CIDR specifies a single address (i.e. a /32 or /128 // for IPV4 and IPV6 CIDRs accordingly). // Calculate number of hosts in network (2^hostBits - 1) or the // equivalent (1 << hostBits) - 1. // Calculate last IP in range. // Convert last IP into bytes. Since BigInt strips off leading zeroes // we need to prepend them again before casting back to net.IP.