Beispiel #1
0
 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;
 }
Beispiel #2
0
 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();
 }
Beispiel #3
0
 /**
  * @dataProvider  linkLocalProvider
  */
 public function testIsLinkLocal($address, $expected)
 {
     $addr = new IPv4($address);
     $this->assertSame($expected, $addr->isLinkLocal());
 }
Beispiel #4
0
 /**
  * 
  * @param \IpUtils\Address\IPv4 $ip
  * @return boolean
  */
 private function isIpv4InUnroutableRange(IPv4 $ip)
 {
     foreach ($this->unrouteableRanges as $ipRange) {
         if ($ip->matches(new Subnet($ipRange))) {
             return true;
         }
     }
     return false;
 }
Beispiel #5
0
 public function validate()
 {
     return \IpUtils\Address\IPv4::isValid($this->_definition);
 }