/****************************************************************************************************************/ /* Description: This snippet is provide simple way to help user Converting IP address ranges into CIDR format */ /* suggestions for different city locations across the country. */ /* There are 1 steps in this snippet. For information, please visit IP2Location tutorial page at: */ /*https://www.ip2location.com/tutorials/how-to-convert-ip-address-range-into-cidr */ /****************************************************************************************************************/ = $start){ $maxSize = 32; while ($maxSize > 0){ $mask = hexdec(iMask($maxSize - 1)); $maskBase = $start & $mask; if($maskBase != $start) break; $maxSize--; } $x = log($end - $start + 1)/log(2); $maxDiff = floor(32 - floor($x)); if($maxSize < $maxDiff){ $maxSize = $maxDiff; } $ip = long2ip($start); array_push($result, "$ip/$maxSize"); $start += pow(2, (32-$maxSize)); } return $result; } function iMask($s){ return base_convert((pow(2, 32) - pow(2, (32-$s))), 10, 16); } ?>