如何使用ipv6网络掩码长度计算ipv4地址的网络掩码长度?

时间:2014-04-22 21:32:10

标签: ipv6 ipv4 subnet

我正在尝试使用网络掩码长度计算范围内的ipv4地址。 例如: 启动IP(v6)::: ffff:1.0.64.0 网络掩码长度:: 114

如何使用前缀长度计算此范围的结束ip(以v4格式)? 对于上面的示例,ips将在1.0.64.0-1.0.127.255范围内 (使用http://www.gestioip.net/cgi-bin/subnet_calculator.cgi

计算得出

由于

维诺德

1 个答案:

答案 0 :(得分:2)

就像使用IPv4一样,您可以通过将前114位设置为1并将其余位设置为0来创建IPv6掩码,然后使用按位AND运算符使用该掩码屏蔽原始IPv6地址获取子网ID(以及子网的起始地址),然后将掩码的反转与子网ID相对应,以获取子网的最后一个地址。

  ::FFFF:1.0.64.0
= 0000:0000:0000:0000:0000:FFFF:0100:4000
= 00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111100000001000000000100000000000000

prefix length 114
= 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000
= FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:C000

    00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111100000001000000000100000000000000
AND 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000
    --------------------------------------------------------------------------------------------------------------------------------
  = 00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111100000001000000000100000000000000

    0000:0000:0000:0000:0000:FFFF:0100:4000
AND FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:C000
    ---------------------------------------
  = 0000:0000:0000:0000:0000:FFFF:0100:4000

  = ::FFFF:1.0.64.0

NOT 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000
    --------------------------------------------------------------------------------------------------------------------------------
  = 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111

NOT FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:C000
    ---------------------------------------
  = 0000:0000:0000:0000:0000:0000:0000:3FFF

    00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111100000001000000000100000000000000
OR  00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111
    --------------------------------------------------------------------------------------------------------------------------------
  = 00000000000000000000000000000000000000000000000000000000000000000000000000000000111111111111111100000001000000000111111111111111

    0000:0000:0000:0000:0000:FFFF:0100:4000
OR  0000:0000:0000:0000:0000:0000:0000:3FFF
    ---------------------------------------
  = 0000:0000:0000:0000:0000:FFFF:0100:7FFF

  = ::FFFF:1.0.127.255