package main
import (
"fmt"
"github.com/lixiangzhong/ipnet"
)
func main() {
ip, err := ipnet.ParseIPv4("1.1.1.1")
if err != nil {
fmt.Println(err)
}
fmt.Println(ip, ip.Int(), ip.Inverse())
ip.ParseInt(111)
fmt.Println(ip)
cidr := ipnet.MustParseCIDR("1.1.1.0/24")
fmt.Println(cidr)
fmt.Println(cidr.Int())
fmt.Println(cidr.IPMask())
fmt.Println(cidr.StartEndIP())
cidr, err = ipnet.IPMaskToCIDR("1.1.0.0", "255.255.0.0")
if err != nil {
fmt.Println(err)
}
fmt.Println(cidr)
fmt.Println(cidr.IPMask())
cidrs, err := ipnet.IPRangeToCIDR("1.1.1.0", "1.1.2.255")
if err != nil {
fmt.Println(err)
}
fmt.Println(cidrs)
}
-
Notifications
You must be signed in to change notification settings - Fork 1
lixiangzhong/ipnet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
cidr与ip之间的转换
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published