Documentation ¶
Overview ¶
Package mapcidr implements methods to allow working with CIDRs.
Index ¶
- Variables
- func AddressCount(cidr string) (uint64, error)
- func AddressCountIpnet(network *net.IPNet) uint64
- func AddressRange(network *net.IPNet) (firstIP, lastIP net.IP, err error)
- func AggregateApproxIPs(ips []*net.IPNet) ([]*net.IPNet, error)
- func AlterIP(ip string, formats []string, zeroPadN int, zeroPadPermutation bool) []string
- func AsIPV4CIDR(ipv4 string) *net.IPNet
- func CIDRsAsIPNET(cidrs []string) (ipnets []*net.IPNet)
- func CoalesceCIDRs(cidrs []*net.IPNet) (coalescedIPV4, coalescedIPV6 []*net.IPNet)
- func CountIPsInCIDR(includeBase, includeBroadcast bool, ipnet *net.IPNet) *big.Int
- func CountIPsInCIDRs(includeBase, includeBroadcast bool, ipnets ...*net.IPNet) *big.Int
- func FixedPad(ip net.IP, padding int) string
- func FmtIP4MappedIP6(ip6 net.IP) string
- func FmtIP4MappedIP6Short(ip6 net.IP) string
- func FmtIp6(ip net.IP, short bool) (string, error)
- func GetCIDRFromIPRange(firstIP, lastIP net.IP) ([]*net.IPNet, error)
- func GetCIDRPrefixesFromIPs(ips []net.IP) []*net.IPNet
- func GetNextIP(ip net.IP) net.IP
- func IPAddresses(cidr string) ([]string, error)
- func IPAddressesAsStream(cidr string) (chan string, error)
- func IPAddressesIPnet(ipnet *net.IPNet) (ips []string)
- func IPToInteger(ip net.IP) (*big.Int, int, error)
- func IPToPrefix(ip net.IP) *net.IPNet
- func IncrementalPad(ip net.IP, padding int) []string
- func Inet_aton(ipnr net.IP) int64
- func Inet_ntoa(ipnr int64) net.IP
- func IntegerToIP(ipInt *big.Int, bits int) net.IP
- func IpAddresses(ipnet *net.IPNet) (ips chan string)
- func IpRangeToCIDR(start, end string) ([]string, error)
- func IsBaseIP(IP string) bool
- func IsBroadcastIP(IP string) bool
- func IsExcluded(excludeList []net.IP, ip net.IP) bool
- func IsIPv4(ip net.IP) bool
- func IsIPv6(ip net.IP) bool
- func KeepUniqueIPs(ips []net.IP) []net.IP
- func PickIP(cidrs []*net.IPNet, index int64) string
- func PickPort(ports []int, index int) int
- func PickSubnetIP(network *net.IPNet, index int64) string
- func RandomHex(n int, suffix []byte) (string, error)
- func RemoveCIDRs(allowCIDRs, removeCIDRs []*net.IPNet) ([]*net.IPNet, error)
- func ShuffleCidrsWithPortsAndSeed(cidrs []*net.IPNet, ports []int, seed int64) chan Item
- func ShuffleCidrsWithSeed(cidrs []*net.IPNet, seed int64) chan Item
- func SplitByNumber(iprange string, number int) ([]*net.IPNet, error)
- func SplitIPNetByNumber(ipnet *net.IPNet, number int) ([]*net.IPNet, error)
- func SplitIPNetIntoN(iprange *net.IPNet, n int) ([]*net.IPNet, error)
- func SplitN(iprange string, n int) ([]*net.IPNet, error)
- func ToIP4(host string) (string, error)
- func ToIP6(host string) (string, error)
- func TotalIPSInCidrs(cidrs []*net.IPNet) (totalIPs uint64)
- type Item
- type NetsByMask
- type NetsByRange
Constants ¶
This section is empty.
Variables ¶
var (
DefaultMaskSize4 = 32
)
var (
ParseIPError error = errors.New("Couldn't parse IP")
)
Functions ¶
func AddressCount ¶
AddressCount returns the number of IP addresses in a range
func AddressCountIpnet ¶
AddressCountIpnet returns the number of IP addresses in an IPNet structure
func AddressRange ¶
AddressRange returns the first and last addresses in the given CIDR range.
func AggregateApproxIPs ¶ added in v1.1.34
func AsIPV4CIDR ¶ added in v0.0.7
AsIPV4CIDR converts ipv4 address to cidr representation
func CIDRsAsIPNET ¶ added in v0.0.7
CIDRsAsIPNET converts a list of cidrs to ipnet
func CoalesceCIDRs ¶ added in v0.0.6
CoalesceCIDRs transforms the provided list of CIDRs into the most-minimal equivalent set of IPv4 and IPv6 CIDRs. It removes CIDRs that are subnets of other CIDRs in the list, and groups together CIDRs that have the same mask size into a CIDR of the same mask size provided that they share the same number of most significant mask-size bits.
Note: this algorithm was ported from the Python library netaddr. https://github.com/drkjam/netaddr .
func CountIPsInCIDR ¶ added in v0.0.6
CountIPsInCIDR takes a RFC4632/RFC4291-formatted IPv4/IPv6 CIDR and determines how many IP addresses reside within that CIDR. Returns 0 if the input CIDR cannot be parsed.
func CountIPsInCIDRs ¶ added in v1.0.0
CountIPsInCIDR counts the number of ips from a group of cidr
func FmtIP4MappedIP6 ¶ added in v1.0.0
FmtIP4MappedIP6 prints an ip4-mapped as ip6 with ip6 format
func FmtIP4MappedIP6Short ¶ added in v1.0.1
func GetCIDRFromIPRange ¶ added in v1.0.2
The intent here is to get the CIDR range from the IP range. This function will return the sorted list of CIDR ranges.
func GetCIDRPrefixesFromIPs ¶ added in v0.0.6
GetCIDRPrefixesFromIPs returns all of the ips as a slice of *net.IPNet.
func GetNextIP ¶ added in v0.0.6
GetNextIP returns the next IP from the given IP address. If the given IP is the last IP of a v4 or v6 range, the same IP is returned.
func IPAddresses ¶ added in v0.0.2
IPAddresses returns all the IP addresses in a CIDR
func IPAddressesAsStream ¶ added in v0.0.8
func IPAddressesIPnet ¶ added in v0.0.2
IPAddressesIPnet returns all IP addresses in an IPNet.
func IPToInteger ¶ added in v0.0.2
IPToInteger converts an IP address to its integer representation. It supports both IPv4 as well as IPv6 addresses.
func IPToPrefix ¶ added in v0.0.6
IPToPrefix returns the corresponding IPNet for the given IP.
func IntegerToIP ¶ added in v0.0.2
IntegerToIP converts an Integer IP address to net.IP format.
func IpAddresses ¶ added in v1.0.0
IpAddresses as stream
func IpRangeToCIDR ¶ added in v1.1.34
func IsBroadcastIP ¶ added in v0.0.9
func IsExcluded ¶ added in v0.0.6
IsExcluded returns whether a given IP is must be excluded due to coming from blacklisted device.
func KeepUniqueIPs ¶ added in v0.0.6
KeepUniqueIPs transforms the provided multiset of IPs into a single set, lexicographically sorted via a byte-wise comparison of the IP slices (i.e. IPv4 addresses show up before IPv6). The slice is manipulated in-place destructively.
1- Sort the slice by comparing the IPs as bytes 2- For every unseen unique IP in the sorted slice, move it to the end of the return slice. Note that the slice is always large enough and, because it is sorted, we will not overwrite a valid element with another. To overwrite an element i with j, i must have come before j AND we decided it was a duplicate of the element at i-1.
func PickSubnetIP ¶ added in v0.0.7
PickSubnetIP takes an ip from a subnet
func RemoveCIDRs ¶ added in v0.0.6
RemoveCIDRs removes the specified CIDRs from another set of CIDRs. If a CIDR to remove is not contained within the CIDR, the CIDR to remove is ignored. A slice of CIDRs is returned which contains the set of CIDRs provided minus the set of CIDRs which were removed. Both input slices may be modified by calling this function.
func ShuffleCidrsWithPortsAndSeed ¶ added in v0.0.7
ShuffleCidrsWithPortsAndSeed uses blackrock to visit all ips and ports combinations in random order
func ShuffleCidrsWithSeed ¶ added in v0.0.7
ShuffleCidrsWithSeed uses blackrock to visit all ips in random order
func SplitByNumber ¶
SplitByNumber splits the given cidr into subnets with the closest number of hosts per subnet.
func SplitIPNetByNumber ¶ added in v0.0.2
SplitIPNetByNumber splits an IPNet into subnets with the closest n umber of hosts per subnet.
func SplitIPNetIntoN ¶ added in v0.0.2
SplitIPNetIntoN attempts to split a ipnet in the exact number of subnets
func TotalIPSInCidrs ¶ added in v0.0.7
TotalIPSInCidrs calculates the number of ips in the diven cidrs
Types ¶
type NetsByMask ¶ added in v0.0.6
NetsByMask is used to sort a list of IP networks by the size of their masks. Implements sort.Interface.
func (NetsByMask) Len ¶ added in v0.0.6
func (s NetsByMask) Len() int
func (NetsByMask) Less ¶ added in v0.0.6
func (s NetsByMask) Less(i, j int) bool
func (NetsByMask) Swap ¶ added in v0.0.6
func (s NetsByMask) Swap(i, j int)
type NetsByRange ¶ added in v0.0.6
type NetsByRange []*netWithRange
NetsByRange is used to sort a list of ranges, first by their last IPs, then by their first IPs Implements sort.Interface.
func (NetsByRange) Len ¶ added in v0.0.6
func (s NetsByRange) Len() int
func (NetsByRange) Less ¶ added in v0.0.6
func (s NetsByRange) Less(i, j int) bool
func (NetsByRange) Swap ¶ added in v0.0.6
func (s NetsByRange) Swap(i, j int)