/** * Returns array with subnets usage stats * * @return array */ function zb_FreeIpStats() { $result = array(); $allServices = array(); $allNets = array(); $nethostsUsed = array(); $servicesTmp = multinet_get_services(); $netsTmp = multinet_get_all_networks(); $neth_q = "SELECT COUNT(id) as count, netid from `nethosts` group by `netid`"; $nethTmp = simple_queryall($neth_q); if (!empty($nethTmp)) { foreach ($nethTmp as $io => $each) { $nethostsUsed[$each['netid']] = $each['count']; } } if (!empty($servicesTmp)) { foreach ($servicesTmp as $io => $each) { $allServices[$each['netid']] = $each['desc']; } } if (!empty($netsTmp)) { foreach ($netsTmp as $io => $each) { $totalIps = multinet_expand_network($each['startip'], $each['endip']); $allNets[$each['id']]['desc'] = $each['desc']; $allNets[$each['id']]['total'] = count($totalIps); //finding used hosts count if (isset($nethostsUsed[$each['id']])) { $allNets[$each['id']]['used'] = $nethostsUsed[$each['id']]; } else { $allNets[$each['id']]['used'] = 0; } //finding network associated service if (isset($allServices[$each['id']])) { $allNets[$each['id']]['service'] = $allServices[$each['id']]; } else { $allNets[$each['id']]['service'] = ''; } } } return $allNets; }
function zb_NetworkGetByIp($ip) { $allnets = multinet_get_all_networks(); $result = false; if (!empty($allnets)) { foreach ($allnets as $io => $eachnet) { $completenet = multinet_expand_network($eachnet['startip'], $eachnet['endip']); if (in_array($ip, $completenet, true)) { $result = $eachnet['id']; break; } else { $result = false; } } } return $result; }