我正在寻找创建一个将ipv6范围或cidr作为输入的脚本,并吐出一个/ 64块列表(或每个/ 64块中的第一个IP).
我有一个功能,可以为IPv4 IP做类似的事情,但我缺乏理解为ipv6重新使用它.
Function BreakTo30($CIDR)
{
$CIDR = explode("/", $CIDR); // this breaks the CIDR block into octlets and /notation
$octet = ip2long($CIDR[0]); //turn the first 3 octets into a long for calculating later
$NumberOf30s = pow(2,(30-$CIDR[1]))-1; //calculate the number of /30s in the CIDR block
$OutputArray = array();
for ($i=-4; $i<4 * $NumberOf30s; $OutputArray[] = (long2ip($octet + ($i += 4)))); //fancy math to output each /30
return $OutputArray; //returns an array of ranges
}
Run Code Online (Sandbox Code Playgroud)
ip2long和long2ip只是ipv4.