Getting number of IPv6 addresses from Ipv6 CIDR in PHP

℡╲_俬逩灬. 提交于 2019-12-13 04:33:31

问题


Is there a way to get the number of IPv6 addresses from a Ipv6 CIDR?

for example: CIDR: 2403:3E00::/32 => need get number of ipv6 addresses: 79228162514264337593543950336


回答1:


An IPv6 address has 128 bits, of which (slightly simplified) a number are dedicated to network address, and the rest are dedicated to host addresses.

In your case, 32 bits are dedicated to the network part (/32), so the other 96 are dedicated to host addresses.

2^(128-32) = 2^96 = 79228162514264337593543950336 hosts



回答2:


2^(128-32) = 2^96 = 79228162514264337593543950336 

is wrong, you still need to

79228162514264337593543950336 - 1 = 79228162514264337593543950335 hosts

PS. sorry I could not comment it to the answer of Joachim because of reputation, this is why I am not much interested in stackoverflow.



来源:https://stackoverflow.com/questions/18302098/getting-number-of-ipv6-addresses-from-ipv6-cidr-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!