Documentation
¶
Index ¶
- Constants
- func IP4Distance(src, dst string) (int64, error)
- func IP4IntToStr(n int64) string
- func IP4StrToInt(s string) int64
- func IPCompare(a, b net.IP) int
- func IPDecr(ip net.IP)
- func IPDecr2(ip net.IP) net.IP
- func IPEqual(a, b net.IP) bool
- func IPIncr(ip net.IP)
- func IPIncr2(ip net.IP) net.IP
- func SortCIDRAsc(cs []*CIDR)
- func SortCIDRDesc(cs []*CIDR)
- type CIDR
- func (c CIDR) Broadcast() net.IP
- func (c CIDR) CIDR() *net.IPNet
- func (c CIDR) Contains(ip string) bool
- func (c CIDR) Each(iterator func(ip string) bool)
- func (c CIDR) EachFrom(beginIP string, iterator func(ip string) bool) error
- func (c CIDR) EndIP() net.IP
- func (c CIDR) Equal(ns string) bool
- func (c CIDR) EqualFold(ns string) bool
- func (c CIDR) IP() net.IP
- func (c CIDR) IPCount() *big.Int
- func (c CIDR) IPRange() (start, end net.IP)
- func (c CIDR) IsIPv4() bool
- func (c CIDR) IsIPv6() bool
- func (c CIDR) IsPureIPv6() bool
- func (c CIDR) Mask() net.IPMask
- func (c CIDR) Network() net.IP
- func (c CIDR) StartIP() net.IP
- func (c CIDR) String() string
- func (c CIDR) SubNetting(method SubNettingMethod, num int) ([]*CIDR, error)
- type SubNettingMethod
Constants ¶
const ( // MethodSubnetNum SubNetting based on the number of subnets MethodSubnetNum = SubNettingMethod(0) // MethodHostNum SubNetting based on the number of hosts MethodHostNum = SubNettingMethod(1) // MethodSubnetMask SubNetting based on the mask prefix length of subnets MethodSubnetMask = SubNettingMethod(2) )
Variables ¶
This section is empty.
Functions ¶
func IP4Distance ¶ added in v0.2.0
IP4Distance return the number of ip between two v4 ip
func IPCompare ¶ added in v0.2.0
IPCompare returns an integer comparing two ip
The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func SortCIDRAsc ¶ added in v0.2.0
func SortCIDRAsc(cs []*CIDR)
SortCIDRAsc sort cidr slice order by ip,mask asc
func SortCIDRDesc ¶ added in v0.2.0
func SortCIDRDesc(cs []*CIDR)
SortCIDRDesc sort cidr slice order by ip,mask desc
Types ¶
type CIDR ¶
type CIDR struct {
// contains filtered or unexported fields
}
CIDR https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
func Parse ¶ added in v0.2.0
Parse parses s as a CIDR notation IP address and mask length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC4632 and RFC4291
func ParseNoError ¶ added in v0.2.0
ParseNoError parses s as a CIDR notation IP address and mask length, but ignores any error. Use with caution.
func SuperNetting ¶
SuperNetting merge network segments, must be contiguous
func (CIDR) CIDR ¶
CIDR returns the normalized network address based on the mask, not the original input.
For example, if the original input was "192.168.1.10/24", this returns a *net.IPNet representing "192.168.1.0/24".
func (CIDR) EqualFold ¶ added in v0.3.0
EqualFold reports whether cidr and ns are the same CIDR (including IPv4-mapped)
func (CIDR) IP ¶
IP returns the normalized IP prefix of the CIDR.
This method returns the IP address after processing IPv4-compatible and IPv4-mapped normalizations,
but unlike Network() method, it does not correct the IP prefix based on the mask.
For example, if the original input was "192.168.1.10/24", this returns "192.168.1.10",
while Network() would return "192.168.1.0" (the network address with host bits set to zero).
func (CIDR) IsIPv6 ¶
IsIPv6 reports whether the CIDR is IPv6 (including IPv4-compatible and IPv4-mapped)
func (CIDR) IsPureIPv6 ¶ added in v0.3.0
IsPureIPv6 reports whether the CIDR is IPv6 (excluding IPv4-compatible and IPv4-mapped)
func (CIDR) Mask ¶
Mask returns the network mask of the CIDR as a net.IPMask.
Note that calling mask.String() directly returns a hex string without separators (e.g., "ffffff00"),
which is not human-readable.
Use net.IP(mask).String() to get a human-readable representation: - for IPv4, dotted decimal notation (e.g., "255.255.255.0") - for IPv6, colon-separated hexadecimal notation (e.g., "ffff:ffff:ffff:ffff::")
func (CIDR) String ¶ added in v0.3.0
String returns the normalized string representation of the CIDR
func (CIDR) SubNetting ¶
func (c CIDR) SubNetting(method SubNettingMethod, num int) ([]*CIDR, error)
SubNetting split network segment based on the number of hosts or subnets
type SubNettingMethod ¶ added in v0.2.0
type SubNettingMethod int