In Maria DB table I have two varbinary(16)
fields that represent IPv6 addresses for the start and end of the IPv6 range.
I want to use PHP to loop between this range and generate each IPv6 address that's within the range. I tried to turn binary to decimal to do the loop and increase the decimal number, but the loop does not produce any iteration.
Any help?
//The $IpStart_v6_FromDb/$IpStart_v6_End Vars are produced with INET6_ATON MariaDB function
$IpStartBin = decbin($IpStart_v6_FromDb);
$IpEndBin = decbin($IpEnd_v6_FromDb);
$ArIpRange = array();
$ArIpRange[] = $IpStartBin;
$x=0;
for(;;)
{
if ($IpStartBin==$IpEndBin) break;
$tLastIpBin = $ArIpRange[$x];
$tNextIpBin = decbin( (bindec($tLastIpBin) + 1) );
if ($tNextIpBin==$IpEndBin) break;
$ArIpRange[] = $tNextIpBin;
$x++;
}
foreach ($ArIpRange as $v)
{
echo "<br>IP range item:<br>".base64_encode($v); //debug
}
[EDIT]
I'm embarrassed to say that I thought the length of an IPv6 address is 64 bits.