private function inRange($ip, $cidr, $range)
    {
        $ipVersion = $this->getIpVersion($ip);
        $binIp = $this->ip2bin($ip);

        $parts = explode('/', $range);
        $net = array_shift($parts);
        $range_cidr = array_shift($parts);


        $netVersion = $this->getIpVersion($net);
        if ($ipVersion !== $netVersion) {
            return false;
        }
        if ($range_cidr === null) {
            $range_cidr = $netVersion === 4 ? static::IPV4_ADDRESS_LENGTH : static::IPV6_ADDRESS_LENGTH;
        }

        $binNet = $this->ip2bin($net);
        if (substr($binIp, 0, $range_cidr) === substr($binNet, 0, $range_cidr) && $cidr >= $range_cidr) {
            return true;
        }
        return false;
    }
private function inRange($ip, $cidr, $range)
    {
        $ipVersion = $this->getIpVersion($ip);
        $binIp = $this->ip2bin($ip);

        $parts = explode('/', $range);
        $net = array_shift($parts);
        $range_cidr = array_shift($parts);


        $netVersion = $this->getIpVersion($net);
        if ($ipVersion !== $netVersion) {
            return false;
        }
        if ($range_cidr === null) {
            $range_cidr = $netVersion === 4 ? static::IPV4_ADDRESS_LENGTH : static::IPV6_ADDRESS_LENGTH;
        }

        $binNet = $this->ip2bin($net);
        if (substr($binIp, 0, $range_cidr) === substr($binNet, 0, $range_cidr) && $cidr >= $range_cidr) {
            return true;
        }
        return false;
    }
private function inRange ( $ ip , $ cidr , $ range ) { $ ipVersion = $ this -> getIpVersion ( $ ip ) ; $ binIp = $ this -> ip2bin ( $ ip ) ; $ parts = explode ( '/' , $ range ) ; $ net = array_shift ( $ parts ) ; $ range_cidr = array_shift ( $ parts ) ; $ netVersion = $ this -> getIpVersion ( $ net ) ; if ( $ ipVersion !== $ netVersion ) { return false ; } if ( $ range_cidr === null ) { $ range_cidr = $ netVersion === 4 ? static :: IPV4_ADDRESS_LENGTH : static :: IPV6_ADDRESS_LENGTH ; } $ binNet = $ this -> ip2bin ( $ net ) ; if ( substr ( $ binIp , 0 , $ range_cidr ) === substr ( $ binNet , 0 , $ range_cidr ) && $ cidr >= $ range_cidr ) { return true ; } return false ; }
Checks whether the IP is in subnet range

@param string $ip an IPv4 or IPv6 address
@param integer $cidr
@param string $range subnet in CIDR format e.g. `10.0.0.0/8` or `2001:af::/64`
@return bool
Checks whether the IP is in subnet range