if (is_bool($rango)) { preg_match_all('/(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})/', $range, $matches); $datosh["rango"] = $matches[1][0] . "->" . $matches[1][1]; //substr($des, $descrip, -1); } $des = fgets($file); $cad = "#"; $pos = strpos($des, $cad); $datosh["descripción"] = null; if (!is_bool($pos)) { $datosh["descripción"] = strtoupper(substr($des, $pos + 1, -1)); $datosh["descripción"] = trim($datosh["descripción"], " \t."); } $datosh["netmask2cidr"] = netmask2cidr($datosh['mascara']); $redSubnet = $datosh["RED"] . "/" . $datosh["netmask2cidr"]; $rango = getEachIpInRange($redSubnet); $numRedes = count($rango); $datosh["rangodeipmin"] = $rango[0]; $datosh["rangodeipmax"] = $rango[$numRedes - 1]; $hosts[] = $datosh; } ////IF // print_r($datosh); } //whileee echo json_encode($hosts); fclose($file); break; case $action === 'GuardarRed': $ipred = $data['ip_red']; $idred = $data['id_red'];
* @param string $cidr * @return array */ function getEachIpInRange($cidr) { $ips = array(); $range = array(); $cidr = explode('/', $cidr); $range['firstIP'] = ip2long($cidr[0]) & -1 << 32 - (int) $cidr[1]; $range['lastIP'] = ip2long($cidr[0]) + pow(2, 32 - (int) $cidr[1]) - 1; for ($ip = $range['firstIP']; $ip <= $range['lastIP']; $ip++) { $ips[] = long2ip($ip); } return $ips; } print_r(getEachIpInRange('82.117.206.176/29')); /* E.g. $ php test.php Array ( [0] => 82.117.206.176 [1] => 82.117.206.177 [2] => 82.117.206.178 [3] => 82.117.206.179 [4] => 82.117.206.180 [5] => 82.117.206.181 [6] => 82.117.206.182 [7] => 82.117.206.183 ) */