当前位置: 首页>>代码示例>>PHP>>正文


PHP Subnets::get_max_hosts方法代码示例

本文整理汇总了PHP中Subnets::get_max_hosts方法的典型用法代码示例。如果您正苦于以下问题:PHP Subnets::get_max_hosts方法的具体用法?PHP Subnets::get_max_hosts怎么用?PHP Subnets::get_max_hosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subnets的用法示例。


在下文中一共展示了Subnets::get_max_hosts方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: calculate_IPv6_calc_results

 /**
  * Calculates IPv6 from cidr
  *
  * @access private
  * @param mixed $cidr
  * @return void
  */
 private function calculate_IPv6_calc_results($cidr)
 {
     # initialize subnets Class
     $Subnets = new Subnets($this->Database);
     # Initialize PEAR NET object
     $this->initialize_pear_net_IPv6();
     # set ip address type
     $out['Type'] = 'IPv6';
     # calculate network details
     $out['Host address'] = $cidr;
     $out['Host address'] = $this->Net_IPv6->compress($out['Host address'], 1);
     $out['Host address (uncompressed)'] = $this->Net_IPv6->uncompress($out['Host address']);
     $mask = $this->Net_IPv6->getNetmaskSpec($cidr);
     $subnet = $this->Net_IPv6->getNetmask($cidr);
     $out['Subnet prefix'] = $this->Net_IPv6->compress($subnet) . '/' . $mask;
     $out['Prefix length'] = $this->Net_IPv6->getNetmaskSpec($cidr);
     # get reverse DNS entries
     $out['Host Reverse DNS'] = $this->reverse_IPv6($out['Host address (uncompressed)']);
     $out['Subnet Reverse DNS'] = $this->reverse_IPv6($subnet, $mask);
     # if IP == subnet clear the Host fields and Host Reverse DNS
     if ($out['Host address'] == $out['Subnet prefix']) {
         $out['Host address'] = '/';
         $out['Host address (uncompressed)'] = '/';
         unset($out['Host Reverse DNS']);
     }
     # /min / max hosts
     $maxIp = gmp_strval(gmp_add(gmp_pow(2, 128 - $mask), $this->ip2long6($subnet)));
     $maxIp = gmp_strval(gmp_sub($maxIp, 1));
     $out['Min host IP'] = $subnet;
     $out['Max host IP'] = $this->long2ip6($maxIp);
     $out['Number of hosts'] = $Subnets->get_max_hosts($mask, "IPv6");
     # set address type
     $out['Address type'] = $this->get_ipv6_address_type($cidr);
     # result
     return $out;
 }
开发者ID:julsoj,项目名称:phpipam,代码行数:43,代码来源:class.Tools.php

示例2: prepare_addresses_to_discover_subnetId

 /**
  * Returns array of all addresses to be scanned inside subnet defined with subnetId
  *
  * @access public
  * @param mixed $subnetId
  * @return void
  */
 public function prepare_addresses_to_discover_subnetId($subnetId, $die)
 {
     # initialize classes
     $Subnets = new Subnets($this->Database);
     //subnet ID is provided, fetch subnet
     $subnet = $Subnets->fetch_subnet(null, $subnetId);
     if ($subnet === false) {
         if ($die) {
             die(json_encode(array("status" => 1, "error" => "Invalid subnet ID provided")));
         } else {
             return array();
         }
     }
     // we should support only up to 4094 hosts!
     if ($Subnets->get_max_hosts($subnet->mask, "IPv4") > 4094 && php_sapi_name() != "cli") {
         if ($die) {
             die(json_encode(array("status" => 1, "error" => "Scanning from GUI is only available for subnets up to /20 or 4094 hosts!")));
         } else {
             return array();
         }
     }
     # set array of addresses to scan, exclude existing!
     $ip = $this->get_all_possible_subnet_addresses($subnet->subnet, $subnet->mask);
     # remove existing
     $ip = $this->remove_existing_subnet_addresses($ip, $subnetId);
     //none to scan?
     if (sizeof($ip) == 0) {
         if ($die) {
             die(json_encode(array("status" => 1, "error" => "Didn't find any address to scan!")));
         } else {
             return array();
         }
     }
     //return
     return $ip;
 }
开发者ID:routenull0,项目名称:phpipam,代码行数:43,代码来源:class.Scan.php

示例3: foreach

 // count usage
 foreach ($out as $k => $s) {
     //check if subnet has slaves and set slaves flag true/false
     $slaves = $Subnets->has_slaves($s->id) ? true : false;
     # fetch all addresses and calculate usage
     if ($slaves) {
         $addresses = $Addresses->fetch_subnet_addresses_recursive($s->id, false);
         $slave_subnets = (array) $Subnets->fetch_subnet_slaves($s->id);
         // save count
         $addresses_cnt = gmp_strval(sizeof($addresses));
         # full ?
         if (sizeof($slave_subnets) > 0) {
             foreach ($slave_subnets as $ss) {
                 if ($ss->isFull == 1) {
                     # calculate max
                     $max_hosts = $Subnets->get_max_hosts($ss->mask, $Subnets->identify_address($ss->subnet), true);
                     # count
                     $count_hosts = $Addresses->count_subnet_addresses($ss->id);
                     # add
                     $addresses_cnt = gmp_strval(gmp_add($addresses_cnt, gmp_sub($max_hosts, $count_hosts)));
                 }
             }
         }
         $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull);
         //Calculate free/used etc
     } else {
         # fetch addresses in subnet
         $addresses_cnt = $Addresses->count_subnet_addresses($s->id);
         # calculate usage
         $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull);
     }
开发者ID:korhaldragonir,项目名称:phpipam,代码行数:31,代码来源:threshold.php

示例4: _

# calculate max mask
$max_new_mask = $Subnets->identify_address($Subnets->transform_to_dotted($subnet->subnet)) == "IPv4" ? 32 : 128;
# die if too small
if ($max_new_mask < $subnet->mask) {
    $Result->show("danger", _("Subnet too small to be splitted"), true, true);
}
$n = 2;
# step
$m = 0;
# array id
//set mask options
for ($mask = $subnet->mask + 1; $mask <= $max_new_mask; $mask++) {
    # set vars
    $opts[$m]['mask'] = $mask;
    $opts[$m]['number'] = $n;
    $opts[$m]['max'] = $Subnets->get_max_hosts($mask, $Subnets->identify_address($Subnets->transform_to_dotted($subnet->subnet)));
    # next
    $m++;
    $n = $n * 2;
    # max number = 16!
    if ($n > 256) {
        $mask = 1000;
    }
}
?>

<!-- header -->
<div class="pHeader"><?php 
print _('Split subnet');
?>
</div>
开发者ID:routenull0,项目名称:phpipam,代码行数:31,代码来源:split.php

示例5: find_unused_addresses_IPv6

 /**
  * Search for unused address space between 2 IPv6 addresses
  *
  * Return unused address range or false if none available
  *
  * @access protected
  * @param int $address1
  * @param int $address2
  * @param int $netmask
  * @param bool $empty (default: false)
  * @param bool $is_subnet (default: false)
  * @param bool $is_broadcast (default: false)
  * @return void
  */
 protected function find_unused_addresses_IPv6($address1, $address2, $netmask, $empty = false, $is_subnet = false, $is_broadcast = false)
 {
     # Initialize PEAR NET object
     $this->initialize_pear_net_IPv6();
     if ($empty) {
         $Subnets = new Subnets($this->Database);
         return array("ip" => $this->transform_to_dotted(gmp_strval($address1)) . " - " . $this->transform_to_dotted(gmp_strval($address2)), "hosts" => $Subnets->get_max_hosts($netmask, "IPv6"));
     } else {
         # calculate diff
         $diff = $this->calculate_address_diff($address1, $address2);
         # /128
         if ($netmask == 128) {
             if ($diff > 1) {
                 return array("ip" => $this->transform_to_dotted(gmp_strval($address1)), "hosts" => 1);
             }
         } elseif ($netmask == 127) {
             if ($diff == 1 && $this->is_network($address1, $netmask)) {
                 return array("ip" => $this->transform_to_dotted($address2), "hosts" => 1);
             } elseif ($diff == 1 && $this->is_broadcast($address2, $netmask)) {
                 return array("ip" => $this->transform_to_dotted($address1), "hosts" => 1);
             } elseif ($diff == 0) {
                 return false;
             } else {
                 return array("ip" => $this->transform_to_dotted($address1), "hosts" => 2);
             }
         } elseif ($diff == 0) {
             return false;
         } elseif ($diff == 1) {
             if ($is_subnet) {
                 return array("ip" => $this->transform_to_dotted(gmp_strval($address1)), "hosts" => 1);
             } elseif ($is_broadcast) {
                 return array("ip" => $this->transform_to_dotted(gmp_strval($address2)), "hosts" => 1);
             } else {
                 return false;
             }
         } elseif ($diff == 2 && !$is_subnet && !$is_broadcast) {
             return array("ip" => $this->transform_to_dotted(gmp_strval(gmp_add($address1, 1))), "hosts" => 1);
         } else {
             if ($is_subnet) {
                 return array("ip" => $this->transform_to_dotted(gmp_strval($address1)) . " - " . $this->transform_to_dotted(gmp_strval(gmp_sub($address2, 1))), "hosts" => $this->reformat_number(gmp_strval(gmp_sub($diff, 0))));
             } elseif ($is_broadcast) {
                 return array("ip" => $this->transform_to_dotted(gmp_strval(gmp_add($address1, 1))) . " - " . $this->transform_to_dotted(gmp_strval($address2)), "hosts" => $this->reformat_number(gmp_strval(gmp_sub($diff, 0))));
             } else {
                 return array("ip" => $this->transform_to_dotted(gmp_strval(gmp_add($address1, 1))) . " - " . $this->transform_to_dotted(gmp_strval(gmp_sub($address2, 1))), "hosts" => $this->reformat_number(gmp_strval(gmp_strval(gmp_sub($diff, 1)))));
             }
         }
         # default false
         return false;
     }
 }
开发者ID:routenull0,项目名称:phpipam,代码行数:64,代码来源:class.Addresses.php


注:本文中的Subnets::get_max_hosts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。