func BroadcastAddr(n *net.IPNet) net.IP {
	broadcast := NewIP(len(n.IP))
	for i := 0; i < len(n.IP); i++ {
		broadcast[i] = n.IP[i] | ^n.Mask[i]
	}
	return broadcast
}
BroadcastAddr returns the last address in the given network, or the broadcast address.
package netaddr
import (
	"bytes"
	"fmt"
	"math/big"
	"net"
	"strings"
)
func NetSize(n *net.IPNet) *big.Int {
	ones, bits := n.Mask.Size()
	return big.NewInt(0).Lsh(big.NewInt(1), uint(bits-ones))
}
func ParseIP(address string) net.IP {
	if strings.Contains(address, ":") {
		return net.ParseIP(address)
	}
	return net.ParseIP(address).To4()
}
func ParseCIDR(cidr string) (net.IP, *net.IPNet, error) {
	ip, ipNet, err := net.ParseCIDR(cidr)
	if err != nil {
		return net.IP{}, nil, err
	}
	if strings.Contains(cidr, ":") {
		return ip, ipNet, nil
	}
	return ip.To4(), ipNet, nil
}
func ParseCIDRToNet(cidr string) (*net.IPNet, error) {
	ip, ipNet, err := ParseCIDR(cidr)
	if err != nil {
		return nil, err
	}
	return &net.IPNet{IP: ip, Mask: ipNet.Mask}, nil
}
func ParseNet(cidr string) (parsed *net.IPNet, err error) {
	ip, parsed, err := net.ParseCIDR(cidr)
	if err != nil {
		return nil, err
	}
	if !ip.Equal(parsed.IP) {
		err = fmt.Errorf("Host part is not zero")
		return nil, err
	}
	return
}
func NewIP(size int) net.IP {
	if size == 4 {
		return net.ParseIP("0.0.0.0").To4()
	}
	if size == 16 {
		return net.ParseIP("::")
	}
	panic("Bad value for size")
}
func NetworkAddr(n *net.IPNet) net.IP {
	network := NewIP(len(n.IP))
	for i := 0; i < len(n.IP); i++ {
		network[i] = n.IP[i] & n.Mask[i]
	}
	return network
}