ipx

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIPv4Uint32 = 4294967295

Variables

View Source
var (
	FirstIPv4 = net.IPv4(0, 0, 0, 0)
	LastIPv4  = net.IPv4(255, 255, 255, 255)
	FirstIPv6 = make(net.IP, net.IPv6len)
	LastIPv6  = net.IP{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

Functions

func Contains

func Contains(start, end, ip net.IP) bool

Contains 检查IP区间内是否包含IP

func IPLess

func IPLess(a, b net.IP) bool

IPLess IP大小比较 IPv4 < IPv6

func IPNetMaskLess

func IPNetMaskLess(a, b *net.IPNet) bool

IPNetMaskLess CIDR大小比较 IPv4 < IPv6 ones越大,子网范围越小

func IPv4StrToUint32

func IPv4StrToUint32(ipStr string) uint32

IPv4StrToUint32 IPv4字符串 转换为 uint32 (syntactic sugar)

func IPv4ToUint32

func IPv4ToUint32(ip net.IP) uint32

IPv4ToUint32 IPv4 转换为 uint32

func IsFirstIP added in v0.1.2

func IsFirstIP(ip net.IP, ipv6 bool) bool

IsFirstIP 是否是起始IP

func IsLastIP added in v0.1.2

func IsLastIP(ip net.IP, ipv6 bool) bool

IsLastIP 是否是最后一个IP

func LastIP

func LastIP(ipNet *net.IPNet) net.IP

LastIP IPNet最后一个IP

func NextIP

func NextIP(ip net.IP) net.IP

NextIP 下一个IP

func PrefixSameLength

func PrefixSameLength(start, end net.IP) int

PrefixSameLength 前缀相同长度

func PrevIP added in v0.1.2

func PrevIP(ip net.IP) net.IP

PrevIP 上一个IP

func SuffixZeroLength

func SuffixZeroLength(ip net.IP) int

SuffixZeroLength 后缀空值长度

func Uint32ToIPv4

func Uint32ToIPv4(uip uint32) net.IP

Uint32ToIPv4 uint32 转换为 IP

func Uint64ToIP added in v0.1.2

func Uint64ToIP(uip uint64) net.IP

Uint64ToIP uint64 转换为 IP

func Uint64ToIP2 added in v0.1.2

func Uint64ToIP2(high, low uint64) net.IP

Uint64ToIP2 uint64 转换为 IP

Types

type Range

type Range struct {
	Start net.IP
	End   net.IP
}

Range IP区间

func NewRange

func NewRange(ipNet *net.IPNet) *Range

NewRange 初始化IP区间 统一成 IPv6 长度进行处理

func (*Range) CommonRange

func (r *Range) CommonRange(ip net.IP, r2 *Range) bool

CommonRange 求共同网段

func (*Range) Contains

func (r *Range) Contains(ip net.IP) bool

Contains 检查IP区间内是否包含IP

func (*Range) IPNets

func (r *Range) IPNets() []*net.IPNet

IPNets 输出IP区间对应的CIDR分组

func (*Range) Join

func (r *Range) Join(r2 *Range) bool

Join 合并网段

func (*Range) JoinIPNet

func (r *Range) JoinIPNet(ipNet *net.IPNet) bool

JoinIPNet 合并网段

type Ranges

type Ranges []Range

func (Ranges) Len

func (r Ranges) Len() int

func (Ranges) Less

func (r Ranges) Less(i, j int) bool

func (Ranges) Swap

func (r Ranges) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL