cidrMatch() публичный статический Метод

The range can contain IPv4 and IPv6 addresses (including IPv6 wrapped IPv4 addresses).
См. также: http://tools.ietf.org/html/rfc4632
См. также: http://tools.ietf.org/html/rfc4291#section-2.3 Example: 127.0.0.0/24 will match all IP addresses from 127.0.0.0 to 127.0.0.255 127.0.0.0/31 and 127.0.0.1/31 will both match the IP addresses 127.0.0.0 and 127.0.0.1 127.0.0.254/31 and 127.0.0.255/31 will both match the IP addresses 127.0.0.254 and 127.0.0.255 1:2::3:4 will match the IPv6 address written as 1:2:0:0:0:0:3:4 or 1:2::3:4 ::7F00:1 will match the address written as 127.0.0.1, ::127.0.0.1 or ::7F00:1 ::1 (IPv6 loopback) will *not* match the address 127.0.0.1
public static cidrMatch ( string $ip, string $range ) : boolean
$ip string The IP to match
$range string The CIDR range pattern to match against
Результат boolean TRUE if the pattern matched, FALSE otherwise
Пример #1
0
 /**
  * Matches a \Neos\Flow\Mvc\RequestInterface against the set IP pattern rules
  *
  * @param RequestInterface $request The request that should be matched
  * @return boolean TRUE if the pattern matched, FALSE otherwise
  * @throws InvalidRequestPatternException
  */
 public function matchRequest(RequestInterface $request)
 {
     if (!isset($this->options['cidrPattern'])) {
         throw new InvalidRequestPatternException('Missing option "cidrPattern" in the Ip request pattern configuration', 1446224520);
     }
     if (!$request instanceof ActionRequest) {
         return false;
     }
     return (bool) IpUtility::cidrMatch($request->getHttpRequest()->getClientIpAddress(), $this->options['cidrPattern']);
 }
 /**
  * Check if the given IP address is from a trusted proxy.
  *
  * @param string $ipAddress
  * @return bool
  */
 protected function ipIsTrustedProxy($ipAddress)
 {
     if (filter_var($ipAddress, FILTER_VALIDATE_IP) === false) {
         return false;
     }
     if ($this->settings['proxies'] === '*') {
         return true;
     }
     foreach ($this->settings['proxies'] as $ipPattern) {
         if (IpUtility::cidrMatch($ipAddress, $ipPattern)) {
             return true;
         }
     }
     return false;
 }
Пример #3
0
 /**
  * @dataProvider validAndInvalidIpPatterns
  * @test
  */
 public function cidrMatchCorrectlyMatchesIpRanges($range, $ip, $expected)
 {
     $this->assertEquals($expected, Ip::cidrMatch($ip, $range));
 }