I have the following code snippet and im trying to detect if an IP address falls into a certain range. Most of the time I have the IP address and the subnet but sometimes I just have the IP address only.
<?php
function CalculateRange($IP,$Subnet=""){
//Calculate subnetmax
if ($Subnet==""){
}
//Calculate max IP
return $MaxIP;
}
//--- IP range
$IPRange = array (
array("address"=>"196.201.26.0","subnet"=>"255.255.252.0"),
array("address"=>"196.202.43.0","subnet"=>"255.255.0.0"),
array("address"=>"196.203.44.0","subnet"=>"255.255.128.0"),
);
//Display MaxIP for each IP and Subnet
foreach ($IPRange as $pair) {
echo "<p>";
echo "For IP:{$pair['address']} with Subnet:{$pair['subnet']}.";
echo "MaxIP is ";
echo CalculateRange($pair['address'],$pair['subnet']);
echo "</p>";
}
?>
My question is how do I calculate MaxIP for the IP and Subnet combo?
The below worked perfectly