code-scan starred go-cidr
2021-02-03 01:10:58 Author: github.com(查看原文) 阅读量:255 收藏

go-cidr

Examples

import "github.com/nytr0gen/go-cidr"

r, err := cidr.NewRange("127.0.0.0/31")
if err != nil {
    panic(err)
}

println(r.String()) // 127.0.0.0
r.Next() // true
println(r.String()) // 127.0.0.1
r.Next() // false
import "github.com/nytr0gen/go-cidr"

r, err := cidr.NewRangeWithBlockSize("127.0.0.0/30", 31)
if err != nil {
    panic(err)
}

for {
    println(r.String()) // 127.0.0.0
    println(r.StringPrefix()) // 127.0.0.0/31

    if !r.Next() {
        break
    }
}
import "github.com/nytr0gen/go-cidr"

ips, err := cidr.List("127.0.0.0/30")
if err != nil {
    panic(err)
}

for _, ip := ips {
    println(ip) // 127.0.0.0
}

文章来源: https://github.com/nytr0gen/go-cidr
如有侵权请联系:admin#unsafe.sh