I have a starting IPv4 IP address 5.39.28.128
(or ::ffff:5.39.28.128
) and I have the IPv6 network mask length 122
, how can I calculate the last IP in the range?
I believe I need to convert the start IP to binary, which I'm doing like below, I don't know where to go from there to get the end IP.
$ipNumber = ip2long('5.39.28.128');
$ipBinary = decbin($ipNumber);
echo $ipBinary; // 101001001110001110010000000
The reason is I'm importing the MaxMind GeoIP database in CSV format into a MySQL database (so MySQL functions can be used if needed). MaxMind no longer provide the end IP, in favour of providing the start IP and the IPv6 network mask length instead.