/** * @return number|string */ public function getHostsCount() { $blockSize = $this->getBlockSize(); if ($this->ip->getVersion() === IP::IP_V4) { return $blockSize > 2 ? $blockSize - 2 : $blockSize; } return $blockSize; }
/** * @return int */ public function count() { if ($this->firstIP->getVersion() === IP::IP_V4) { $count = $this->lastIP->toLong() - $this->firstIP->toLong(); } else { $count = bcsub($this->lastIP->toLong(), $this->firstIP->toLong()); } return $count; }
/** * @param int $prefixLength * @return array * @throws \Exception */ public function moveTo($prefixLength) { $maxPrefixLength = $this->ip->getMaxPrefixLength(); if ($prefixLength <= $this->getPrefixLength() || $prefixLength > $maxPrefixLength) { throw new \Exception('Invalid prefix length '); } $netmask = self::prefix2netmask($prefixLength, $this->ip->getVersion()); $networks = array(); $subnet = clone $this; $subnet->setPrefixLength($prefixLength); while ($subnet->ip->inAddr() <= $this->getLastIP()->inAddr()) { $networks[] = $subnet; $subnet = new self($subnet->getLastIP()->next(), $netmask); } return $networks; }