public function __construct($expression) { $expression = strtolower(trim($expression)); if (IPv4::isValid($expression)) { $ip = new IPv4($expression); } elseif (IPv6::isValid($expression)) { $ip = new IPv6($expression); } else { throw new InvalidExpressionException('Expression must be either a valid IPv4 or IPv6 address.'); } $this->expression = $ip->getCompact(); }
public function __construct($expression) { if (strpos($expression, '/') === false) { throw new InvalidExpressionException('Invalid subnet expression "' . $expression . '" given.'); } list($lower, $netmask) = explode('/', $expression, 2); if (strpos($netmask, '.') !== false || strpos($netmask, ':') !== false) { throw new InvalidExpressionException('Netmasks may not use the IP address format ("127.0.0.1/255.0.0.0").'); } // check IP format first if (IPv4::isValid($lower)) { $ip = new IPv4($lower); } elseif (IPv6::isValid($lower)) { $ip = new IPv6($lower); } else { throw new InvalidExpressionException('Subnet expression "' . $expression . '" contains an invalid IP.'); } // now we can properly handle the netmask range $netmask = (int) $netmask; if (!$ip::isValidNetmask($netmask)) { throw new InvalidExpressionException('Invalid or out of range netmask given.'); } $this->lower = $ip; $this->netmask = $netmask; }
public function testGetLoopback() { $this->assertTrue(IPv6::getLoopback()->isLoopback()); }
public function validate() { return \IpUtils\Address\IPv6::isValid($this->_definition); }