IP Check for IPv4

@param string   User IP
@return boolean true when own IP found in localconfig definitions
@access protected
12823
protected function checkIPv4($UserIP = false)
	{
		// Check if IP present
		if ($UserIP === false)
		{
			return false; // No IP, no search.
		}
		// search for user bot IP-filter definitions in localconfig.php
		if (isset($GLOBALS['DLSTATS']['BOT_IPV4']))
		{
			foreach ($GLOBALS['DLSTATS']['BOT_IPV4'] as $lineleft)
			{
				$network = explode("/", trim($lineleft));
				if (! isset($network[1]))
				{
					$network[1] = 32;
				}
				if ($this->dlstatsIPv4InNetwork($UserIP, $network[0], $network[1]))
				{
					return true; // IP found
				}
			}
		}
		return false;
	}
1182492
public function isValidIP4(string $ipAddress): bool
    {
        return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE);
    }
222556
public static function ip($check, $type = 'both')
    {
        $type = strtolower($type);
        $flags = 0;
        if ($type === 'ipv4') {
            $flags = FILTER_FLAG_IPV4;
        }
        if ($type === 'ipv6') {
            $flags = FILTER_FLAG_IPV6;
        }

        return (bool)filter_var($check, FILTER_VALIDATE_IP, ['flags' => $flags]);
    }
839995
public function check() {
        if (empty($this->_ips[$this->_ip])) {
            $this->_ips[$this->_ip] = [];
            $this->_ips[$this->_ip]['time'] = 0;
        }

        if ($this->_exception == false) {
            if (intval($this->_ips[$this->_ip]['time']) + intval($this->config['user']['security']['spam']['config']['query']['duration']) < time()) {
                $this->_updateIp(time(), 1);

                return true;
            }
            elseif ($this->_ips[$this->_ip]['number'] <= $this->config['user']['security']['spam']['config']['query']['number']) {
                $this->_updateIp($this->_ips[$this->_ip]['time'], intval($this->_ips[$this->_ip]['number']) + 1);

                return true;
            }
            else {
                $t = new Template($this->config['user']['security']['spam']['config']['error']['template'], 'core-security-spam', 0);

                foreach ($this->config['user']['security']['spam']['config']['error']['variable'] as $key => $value) {
                    if ($value['type'] == 'var') {
                        $t->assign([$key => $value['value']]);
                    }
                    else {
                        $t->assign([$key => $this->useLang($value['value'])]);
                    }
                }

                echo $t->show();

                $this->addError($this->_ip . ' : exceeded the number of queries allowed for the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action, __FILE__, __LINE__, ERROR_ERROR);

                return false;
            }
        }

        return true;
    }
741264
protected static function checkBotIPv6($UserIP = false, $Bot_IPv6_List = false)
    {
        if (false === $Bot_IPv6_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-ipv6
        if (file_exists($Bot_IPv6_List))
        {
            $source = file($Bot_IPv6_List);
            foreach ($source as $line)
            {
                if ($line[0] === '#') 
                {
                	continue;
                }
                $lineleft = explode("#", $line); // Abtrennen IP von Bemerkung
                $network = explode("/", trim($lineleft[0]));

                if (!isset($network[1]))
                {
                    $network[1] = 128;
                }
                if (static::checkIp6InNetwork($UserIP,$network[0],$network[1]))
                {
                    return true; // IP found
                }
            }
        }
        // search for user bot IP-filter definitions in localconfig.php
        if ( isset($GLOBALS['BOTDETECTION']['BOT_IPV6']) )
        {
            foreach ($GLOBALS['BOTDETECTION']['BOT_IPV6'] as $lineleft)
            {
                $network = explode("/", trim($lineleft));
                if (!isset($network[1]))
                {
                    $network[1] = 128;
                }
                if (static::checkIp6InNetwork($UserIP,$network[0],$network[1]))
                {
                    return true; // IP found
                }
            }
        }
        return false;
    }
1073523
public static function validateIP( $v ) {
		// if integer then convert to string
		if( $ip = filter_var($v, FILTER_VALIDATE_INT) )
			$v = long2ip($ip);
		return filter_var($v, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
	}
281176
protected function authIps($userIp)
    {
        if (empty($this->ips)) {
            return true;
        }

        foreach ($this->ips as $ip) {
            if ($userIp === $ip) {
                return true;
            }
        }

        return false;
    }
1020927
public boolean checkIP(String ipstring)
    {
        Boolean ipconstrain = (Boolean) ips.get(ipstring);
        if (ipconstrain != null)
        {
            return ipconstrain.booleanValue();
        }
        else
        {
            return standard;
        }
    }
320150
public static function isSameOrAnonymizedIp($ip, $currentIp)
    {
        $ip = array_reverse(explode('.', $ip));
        $currentIp = array_reverse(explode('.', $currentIp));

        if (count($ip) != count($currentIp)) {
            return false;
        }

        foreach ($ip as $i => $byte) {
            if ($byte == 0) {
                $currentIp[$i] = 0;
            } else {
                break;
            }
        }

        foreach ($ip as $i => $byte) {
            if ($byte != $currentIp[$i]) {
                return false;
            }
        }
        return true;
    }
391716
def _is_ipv4(self, ip):
        
        try:
            p = IPy.IP(ip)
        except ValueError:
            return False

        if p.version() == 4:
            return True
        return False
347483
public static function isIp($input = false) {

        if ($input && !filter_var($input, FILTER_VALIDATE_IP) === false) {

            return true;
        }

        return false;
    }
689274
public function isIpWhitelisted($ipAddress)
    {
        // determine whether this IP is IPv4 or IPv6
        $isIpv4Address = filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
        return $this->isIpInWhitelist(
            ($isIpv4Address) ? $this->ipv4Whitelist : $this->ipv6Whitelist,
            $ipAddress
        );
    }
723620
public static function validateIP($ip) {
        if (strtolower($ip) === 'unknown')
            return false;

        // generate ipv4 network address
        $ip = ip2long($ip);

        // if the ip is set and not equivalent to 255.255.255.255
        if ($ip !== false && $ip !== -1) {
            // make sure to get unsigned long representation of ip
            // due to discrepancies between 32 and 64 bit OSes and
            // signed numbers (ints default to signed in PHP)
            $ip = sprintf('%u', $ip);
            // do private network range checking
            if ($ip >= 0 && $ip <= 50331647)
                return false;
            if ($ip >= 167772160 && $ip <= 184549375)
                return false;
            if ($ip >= 2130706432 && $ip <= 2147483647)
                return false;
            if ($ip >= 2851995648 && $ip <= 2852061183)
                return false;
            if ($ip >= 2886729728 && $ip <= 2887778303)
                return false;
            if ($ip >= 3221225984 && $ip <= 3221226239)
                return false;
            if ($ip >= 3232235520 && $ip <= 3232301055)
                return false;
            if ($ip >= 4294967040)
                return false;
        }
        return true;
    }
395065
protected function isValidIpAddress($ip)
    {
        $flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
        if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) {
            return false;
        }
        return true;
    }
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;
    }
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;
    }
4934
public function isIPAddressInSubnet($ip_address_string)
    {
        $ip_address = ip2long($ip_address_string);
        list($start_ip, $end_ip) = $this->getIPAddressRangeAsInts();

        return $ip_address >= $start_ip && $ip_address <= $end_ip
            ? true
            : false;
    }