Ejemplo n.º 1
0
 function split_IP($subnet = 0)
 {
     if (isset($this->ip)) {
         $divisor = pow(2, $subnet - $this->netmask);
         $split_arr = array();
         if ($divisor < 1) {
             echo "SUBNET SPLIT IS INVALID";
             exit;
         }
         if ($divisor > 10000) {
             echo "This is very CPU intesive, you have over 10000 splits, try a smaller amounts first thanks!";
             exit;
         }
         $add = "0";
         if ($this->family == 4) {
             $increment = Netblock::binary_add(str_pad("", 32 - $subnet, 1, STR_PAD_RIGHT), "1");
             for ($i = 0; $i < $divisor; $i++) {
                 $bin = Netblock::binary_add($this->bin_network, $add);
                 $add = Netblock::binary_add($increment, $add);
                 //echo $bin." ".long2ip(bindec($bin))."/".$subnet."<br/>";
                 $split_arr[$i] = long2ip(bindec($bin)) . "/" . $subnet;
             }
         } else {
             if ($this->family == 6) {
                 $increment = Netblock::binary_add(str_pad("", 128 - $subnet, 1, STR_PAD_RIGHT), "1");
                 for ($i = 0; $i < $divisor; $i++) {
                     $bin = Netblock::binary_add($this->bin_network, $add);
                     $add = Netblock::binary_add($increment, $add);
                     //echo $bin." ".Netblock::bin_to_ip6(($bin))."/".$subnet."<br/>";
                     $split_arr[$i] = Netblock::bin_to_ip6($bin) . "/" . $subnet;
                 }
             }
         }
         if (!empty($split_arr)) {
             $this->split = $split_arr;
             return $split_arr;
         } else {
             echo "NOT SPLITT-ABLE";
         }
     }
 }