示例#1
0
 /**
  * Does IP Address Match?
  *
  * @param  \Darsyn\IP\IP $clientIp
  * @return boolean
  */
 protected function doesIpAddressMatch(IP $clientIp)
 {
     foreach ($this->ipAddresses as $ipAddress) {
         try {
             $cidr = 128;
             if (preg_match('#^(.+)/([1-9]\\d{0,2})$#', $ipAddress, $matches)) {
                 $ipAddress = $matches[1];
                 $cidr = (int) $matches[2];
             }
             $ipAddress = new IP($ipAddress);
             if ($ipAddress->inRange($clientIp, min($ipAddress->isVersion(IP::VERSION_4) ? $cidr + 96 : $cidr, 128))) {
                 return true;
             }
         } catch (\InvalidArgumentException $e) {
             continue;
         }
     }
     return false;
 }
示例#2
0
文件: IPTest.php 项目: darsyn/ip
 /**
  * Test: Not In Range
  *
  * @test
  * @dataProvider notInRangeIPs
  * @access public
  * @param string $ip1
  * @param string $ip2
  * @param integer $cidr
  * @return void
  */
 public function notInRange($ip1, $ip2, $cidr)
 {
     $ip1 = new IP($ip1);
     $ip2 = new IP($ip2);
     $this->assertFalse($ip1->inRange($ip2, 96 + $cidr));
 }