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 IPEqual(a, b net.IP) bool
- func IPIncr(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) Equal(ns string) bool
- func (c CIDR) IP() net.IP
- func (c CIDR) IPCount() *big.Int
- func (c CIDR) IPRange() (begin, end net.IP)
- func (c CIDR) IsIPv4() bool
- func (c CIDR) IsIPv6() bool
- func (c CIDR) Mask() net.IP
- func (c CIDR) MaskSize() (ones, bits int)
- func (c CIDR) Network() net.IP
- 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) )
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
func SuperNetting ¶
SuperNetting merge network segments, must be contiguous
func (CIDR) CIDR ¶
CIDR returns the CIDR string. If the IP prefix of the input CIDR string is inaccurate, it returns the string which be corrected by the mask length.
For example, "192.0.2.10/24" return "192.0.2.0/24"
func (CIDR) EachFrom ¶ added in v0.2.0
EachFrom begin with specified ip, iterate through each ip in 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