Return TRUE if IPv4 address exists in DNSBL
@return bool
@param $ip string
329989
function blacklisted($ip) {
		if ($this->hive['DNSBL'] &&
			!in_array($ip,
				is_array($this->hive['EXEMPT'])?
					$this->hive['EXEMPT']:
					$this->split($this->hive['EXEMPT']))) {
			// Reverse IPv4 dotted quad
			$rev=implode('.',array_reverse(explode('.',$ip)));
			foreach (is_array($this->hive['DNSBL'])?
				$this->hive['DNSBL']:
				$this->split($this->hive['DNSBL']) as $server)
				// DNSBL lookup
				if (checkdnsrr($rev.'.'.$server,'A'))
					return TRUE;
		}
		return FALSE;
	}
228304
public function contains($ip_or_block): bool
    {
        if ((is_string($ip_or_block) && strpos($ip_or_block, '/') !== false) || $ip_or_block instanceof IPBlock) {
            return $this->containsBlock($ip_or_block);
        } else {
            return $this->containsIP($ip_or_block);
        }
    }
1288910
public function setIP($ip)
    {
        $this->logger->debug('setting: set IP address to ' . $ip);
        $this->ip = $ip;
        return true;
    }
869765
static function isPrivateIP(string $ip)
    {
        if (strncmp($ip, "10.", 3) == 0 or strncmp($ip, "192.168.", 8) == 0)
        {
            return true;
        }
        if (strncmp($ip, "172.", 4) == 0)
        {
            $arr = explode('.', $ip);
            if ($arr[1] >= 16 and $arr[1] <= 31)
            {
                return true;
            }
        }
        return false;
    }
621085
public function set($ip)
    {
        if (is_long($ip)) {
            $ip = long2ip($ip);
        }

        Assertion::ip($ip);

        $this->callMethod('setip', compact('ip'));

        return true;
    }
538462
private function isAllowed($ip) {
        // Look for a wildcard
        if (in_array('*', $this->params['allow'])) {
            // There is a wildcard in the list, all IP's are allowed
            return true;
        }

        // Remove IP's which is not of the same type as $ip before matching
        if ($this->isIPv6($ip)) {
            $list = array_filter($this->params['allow'], [$this, 'isIPv6']);
        } else {
            $list = array_filter($this->params['allow'], [$this, 'isIPv4']);
        }

        foreach ($list as $range) {
            if ((strpos($range, '/') !== false && $this->cidrMatch($ip, $range)) || $ip === $range) {
                return true;
            }
        }

        return false;
    }
1345465
public function ipValidate($ip)
    {
        $this->debug->info(__FUNCTION__, 'IP: ' . json_encode($ip));
        if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
            $this->debug->info(__FUNCTION__, 'Valid is FALSE');

            return FALSE;
        }
        $this->debug->info(__FUNCTION__, 'Valid is TRUE');

        return TRUE;
    }
1256198
public static function isValid(string $ip = null)
    {
        if (is_null($ip)) {
            $ip = self::get();
        }

        return filter_var($ip, FILTER_VALIDATE_IP) == $ip;
    }
1061292
public function isValidIP4NoPrivate(string $ipAddress): bool
    {
        return (bool) filter_var(
            $ipAddress,
            FILTER_VALIDATE_IP,
            FILTER_FLAG_IPV4
            | FILTER_FLAG_NO_PRIV_RANGE
            | FILTER_FLAG_NO_RES_RANGE
        );
    }
585943
private function ip($ip)
    {
        return ((false === ip2long($ip)) || (long2ip(ip2long($ip)) !== $ip)) ? false : true;
    }
1177265
public function checkIP($UserIP = false)
	{
	    // Check if IP present
	    if ($UserIP === false)
	    {
	        $tempIP = $this->dlstatsGetUserIP();
	        if ($tempIP !== false)
	        {
	            $this->IP = $tempIP;
	        }
	        else
	        {
	            return false; // No IP, no search.
	        }
	    }
	    else
	    {
	        $this->IP = $UserIP;
	    }
	    // IPv4 or IPv6 ?
	    switch ($this->checkIPVersion($this->IP))
	    {
	    	case "IPv4":
	    	    if ($this->checkIPv4($this->IP) === true)
	    	    {
	    	        $this->IP_Filter = true;
	    	        return $this->IP_Filter;
	    	    }
	    	    break;
	    	case "IPv6":
	    	    if ($this->checkIPv6($this->IP) === true)
	    	    {
	    	        $this->IP_Filter = true;
	    	        return $this->IP_Filter;
	    	    }
	    	    break;
	    	default:
	    	    $this->IP_Filter = false;
	    	    return $this->IP_Filter;
	    	    break;
	    }
	    $this->IP_Filter = false;
	    return $this->IP_Filter;
	}
901271
protected function validateIp($ip)
    {
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_IPV6) === false) {
            return false;
        }

        return true;
    }
842730
public function getIpVersion($ip)
    {
        if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return self::IPv6;
        }

        else if (false !== filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return self::IPv4;
        }
        // invalid ip
        return false;
    }
244842
public function validIpv6($ip, $strict = true)
    {
        $flags = FILTER_FLAG_IPV6;
        if ($strict) {
            $flags = FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE;
        }

        if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' => $flags)) !== false) {
            return true;
        }

        return false;
    }
953733
public function match( $ip ) {
		$raw = AtEase::quietCall( 'inet_pton', $ip );
		if ( $raw === false ) {
			return false;
		}

		$rawOrd = array_map( 'ord', str_split( $raw ) );
		if ( count( $rawOrd ) == 4 ) {
			$node =& $this->root4;
		} else {
			$node =& $this->root6;
		}

		$curBit = 0;
		while ( $node !== true && $node !== false ) {
			if ( isset( $node['comp'] ) ) {
				// compressed node, matches 1 whole byte on a byte boundary
				if ( $rawOrd[$curBit >> 3] != $node['comp'] ) {
					return false;
				}
				$curBit += 8;
				$node =& $node['next'];
			} else {
				// uncompressed node, walk in the correct direction for the current bit-value
				$maskShift = 7 - ( $curBit & 7 );
				$node =& $node[( $rawOrd[$curBit >> 3] & ( 1 << $maskShift ) ) >> $maskShift];
				++$curBit;
			}
		}

		return $node;
	}
98693
protected static function checkBotIPv4($UserIP = false, $Bot_IPv4_List = false)
    {
        if (false === $Bot_IPv4_List) 
        {
        	return false;
        }
        // Check if IP present
        if ($UserIP === false)
        {
            if (\Environment::get('remoteAddr'))
            {
                if (strpos(\Environment::get('remoteAddr'), ',') !== false) //first IP
                {
                    $UserIP =  trim(substr(\Environment::get('remoteAddr'), 0, strpos(\Environment::get('remoteAddr'), ',')));
                }
                else
                {
                    $UserIP = trim(\Environment::get('remoteAddr'));
                }
            }
            else
            {
                return false; // No IP, no search.
            }
        }
        // search user IP in bot-ip-list
        if (file_exists($Bot_IPv4_List))
        {
            $source = file($Bot_IPv4_List);
            foreach ($source as $line)
            {
                if ($line[0] === '#')
                {
                    continue;
                }
                $lineleft = explode("#", $line); // Abtrennen Netzwerk/Mask von Bemerkung
                $network = explode("/", trim($lineleft[0]));
                if (!isset($network[1]))
                {
                    $network[1] = 32;
                }
                if (static::checkIp4InNetwork($UserIP,$network[0],$network[1]))
                {
                    return true; // IP found
                }
            }
        }
        // search for user bot IP-filter definitions in localconfig.php
        if ( isset($GLOBALS['BOTDETECTION']['BOT_IP']) )
        {
            foreach ($GLOBALS['BOTDETECTION']['BOT_IP'] as $lineleft)
            {
                $network = explode("/", trim($lineleft));
                if (!isset($network[1]))
                {
                    $network[1] = 32;
                }
                if (static::checkIp4InNetwork($UserIP,$network[0],$network[1]))
                {
                    return true; // IP found
                }
            }
        }
        return false;
    }
467693
public static function compressIp($ip)
    {
        if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            return current(unpack('A4', inet_pton($ip)));
        }
        elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            return current(unpack('A16', inet_pton($ip)));
        }
        return false;
    }