/*
Check if IP filter is active
331587
public function isAvailable($quote = null)
    {
        $isAvailable = parent::isAvailable($quote);
        // check if ip range is enabled
        $ipFilter = $this->_getConfigData('ip_filter', 'adyen_pos_cloud');

        if ($isAvailable && $ipFilter != 0) {
            $ip = Mage::helper('adyen')->getClientIp();
            switch ($ipFilter) {
                case '1':
                    // check if ip in in list
                    $_list = $this->_getConfigData('ip_filter_ips', 'adyen_pos_cloud');
                    $_list = str_replace(' ', '', $_list);
                    $_list = explode(',', $_list);
                    $isAvailable = in_array($ip, $_list);
                    break;
                case '2':
                default:
                    // check if ip is in range
                    $from = $this->_getConfigData('ip_filter_from', 'adyen_pos_cloud');
                    $to = $this->_getConfigData('ip_filter_to', 'adyen_pos_cloud');
                    $isAvailable = Mage::helper('adyen')->ipInRange($ip, $from, $to);
                    break;
            }
        }

        return $isAvailable;
    }
439914
def check_client_ip(self, rule):
        """"""

        if not rule.get('from'):
            self.logdebug('no "from" requirement.\n')
            return True

        allow_from = rule.get('from')
        if not isinstance(allow_from, list):
            allow_from = [allow_from]
        client_ip = self.get_client_ip()

        if client_ip in allow_from:
            self.logdebug('client_ip %s in %s\n' % (client_ip, allow_from))
            return True
        else:
            self.logdebug('client_ip %s not in %s' % (client_ip, allow_from))
            return False
760158
def is_device_connected(self, ip):
        
        all_devices = self.get_all_connected_devices()
        for device in all_devices:
            if ip == device['ipaddress']:
                return device['active'] == 1
        return False
468183
def ipinfo_ip_check(ip):
    """"""
    if not is_IPv4Address(ip):
        return None

    response = requests.get('http://ipinfo.io/%s/json' % ip)
    return response.json()
1099508
def check_ip(original_ip):
    '''
    
    ''' 
    ip = original_ip.strip()
    parts = ip.split('.')
    if len(parts) != 4:
        return None
    for p in parts:
        try:
            p = int(p)
            if (p < 0) or (p > 255):
                return None
        except:
            return None
    return ip
1234973
def _ip_is_usable(self, current_ip):
        
        # Consider IP addresses only.
        try:
            ipaddress.ip_address(current_ip)
        except ValueError:
            return False

        # Never use real IP.
        if current_ip == self.real_ip:
            return False

        # Do dot allow IP reuse.
        if not self._ip_is_safe(current_ip):
            return False

        return True
889054
def detect(self):
        
        theip = find_ip(family=self.opts_family)
        self.set_current_value(theip)
        return theip
176289
@Override
    public boolean check(String[] pHostOrAddresses) {
        if (allowedHostsSet == null) {
            return true;
        }
        for (String addr : pHostOrAddresses) {
            if (allowedHostsSet.contains(addr)) {
                return true;
            }
            if (allowedSubnetsSet != null && IP_PATTERN.matcher(addr).matches()) {
                for (String subnet : allowedSubnetsSet) {
                    if (IpChecker.matches(subnet, addr)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
149445
def is_reserved(ip):
    
    if ip_between(ip, "0.0.0.0", "0.255.255.255"):
        return True
    elif ip_between(ip, "10.0.0.0", "10.255.255.255"):
        return True
    elif ip_between(ip, "100.64.0.0", "100.127.255.255"):
        return True
    elif ip_between(ip, "127.0.0.0", "127.255.255.255"):
        return True
    elif ip_between(ip, "169.254.0.0", "169.254.255.255"):
        return True
    elif ip_between(ip, "172.16.0.0", "172.31.255.255"):
        return True
    elif ip_between(ip, "192.0.0.0", "192.0.0.255"):
        return True
    elif ip_between(ip, "192.0.2.0", "192.0.2.255"):
        return True
    elif ip_between(ip, "192.88.99.0", "192.88.99.255"):
        return True
    elif ip_between(ip, "192.168.0.0", "192.168.255.255"):
        return True
    elif ip_between(ip, "198.18.0.0", "198.19.255.255"):
        return True
    elif ip_between(ip, "198.51.100.0", "198.51.100.255"):
        return True
    elif ip_between(ip, "203.0.113.0", "203.0.113.255"):
        return True
    elif ip_between(ip, "224.0.0.0", "255.255.255.255"):
        return True
    else:
        return False
454247
public function filter_ip( ){

		// get IP
		$ip = $_SERVER['REMOTE_ADDR'];
		if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		}

		return $ip;

	}
1359093
public function isPrivate(): bool
    {
        if ($this->isLoopback()) {
            return true;
        }

        $filtered = filter_var(
            $this->address,
            FILTER_VALIDATE_IP,
            FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
        );

        return $filtered === false;
    }
165074
def contains(ip)
			if (!ip.kind_of?(IPv6))
				raise ArgumentError, "Expected an IPv6 object for 'ip' but got a #{ip.class}."
			end
			if (@base.addr == ip.addr & @m128.mask)
				return true
			end
			return false
		end
1146928
public boolean inRange(InetAddress ip) throws FilterException {
        Iterator iter = ranges.iterator();
        while (iter.hasNext()) {
            IPAddressRange range = (IPAddressRange) iter.next();
            if (range.inRange(ip)) {
                return true;
            }
        }

        return false;
    }
122238
private function isIpBlacklisted()
    {
        $blacklist = $this->config->get('RateLimitBlacklist', [], true);
        if (in_array($this->ip, $blacklist)) {
            return true;
        }

        return false;
    }
1023802
private boolean isAllowedAddress(String ipAddress) {
        if (allowedAddresses == null) {
            return false;
        }

        // IPv4
        int offset = ipAddress.lastIndexOf('.');
        if (offset == -1) {
            // IPv6
            offset = ipAddress.lastIndexOf(':');
            if (offset == -1) {
                return false;
            }
        }

        String ipAddressClass = ipAddress.substring(0, offset + 1) + '*';
        return (allowedAddresses.contains(ipAddressClass) || allowedAddresses.contains(ipAddress));
    }
1020927
public boolean checkIP(String ipstring)
    {
        Boolean ipconstrain = (Boolean) ips.get(ipstring);
        if (ipconstrain != null)
        {
            return ipconstrain.booleanValue();
        }
        else
        {
            return standard;
        }
    }
734700
@Override
    public FetchStatus checkFilter(URI uri) {
        if (uri == null) {
            return FetchStatus.OUT_OF_SCOPE;
        }

        String otherScheme = normalisedScheme(uri.getRawScheme());
        if (port != normalisedPort(otherScheme, uri.getPort())) {
            return FetchStatus.OUT_OF_SCOPE;
        }

        if (!scheme.equals(otherScheme)) {
            return FetchStatus.OUT_OF_SCOPE;
        }

        if (!hasSameHost(uri)) {
            return FetchStatus.OUT_OF_SCOPE;
        }

        if (!startsWith(uri.getRawPath(), path)) {
            return FetchStatus.OUT_OF_SCOPE;
        }

        return FetchStatus.VALID;
    }