IpMask > CIDR

ones, bits := net.IPv4Mask(255, 255, 255, 248).Size()
fmt.Println(ones,bits)

CIDR > IpMask

_, ipNet, err := net.ParseCIDR("10.95.134.192/29")
    if err != nil {
        fmt.Println(err)
    }
    val := make([]byte, len(ipNet.Mask))
    copy(val, ipNet.Mask)

    var s []string
    for _, i := range val[:] {
        s = append(s, strconv.Itoa(int(i)))
    }
    fmt.Printf("%s/%s\n", ipNet.IP, strings.Join(s, "."))

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code