/** * @return Network */ public function getSpanNetwork() { $xorIP = IP::parseInAddr($this->getFirstIP()->inAddr() ^ $this->getLastIP()->inAddr()); preg_match('/^(0*)/', $xorIP->toBin(), $match); $prefixLength = strlen($match[1]); $ip = IP::parseBin(str_pad(substr($this->getFirstIP()->toBin(), 0, $prefixLength), $xorIP->getMaxPrefixLength(), '0')); return new Network($ip, Network::prefix2netmask($prefixLength, $ip->getVersion())); }
/** * @return IP */ public function getLastHost() { $broadcast = $this->getBroadcast(); if ($broadcast->getVersion() === IP::IP_V4) { if ($this->getBlockSize() > 2) { return IP::parseBin(substr($broadcast->toBin(), 0, $broadcast->getMaxPrefixLength() - 1) . '0'); } } return $broadcast; }
/** * @return Range */ public function getHosts() { $firstHost = $this->getNetwork(); $lastHost = $this->getBroadcast(); if ($this->ip->getVersion() === IP::IP_V4) { if ($this->getBlockSize() > 2) { $firstHost = IP::parseBin(substr($firstHost->toBin(), 0, $firstHost->getMaxPrefixLength() - 1) . '1'); $lastHost = IP::parseBin(substr($lastHost->toBin(), 0, $lastHost->getMaxPrefixLength() - 1) . '0'); } } return new Range($firstHost, $lastHost); }