Attempts to find a country from the IP address.
@param string $ipAddress
@return self
966217
public static function getFromIp($ipAddress)
    {
        try {
            $body = (string) Http::get('http://ip2c.org/?ip='.$ipAddress);

            if (substr($body, 0, 1) === '1') {
                $code = explode(';', $body)[1];
                return static::where('code', $code)->first();
            }
        }
        catch (Exception $e) {}
    }
463940
def getIPaddresses(self):
        """"""
        if not self.ipAddress:
            self.ipAddress = ipAddresses.getAll() # update with IP address
        return self.ipAddress
536546
protected function loadIpThrottles($ipAddress)
    {
        $queryBuilder = $this->getEntityManager()->createQueryBuilder();

        $queryBuilder
            ->select('t')
            ->from($this->entityName('ip'), 't')
            ->where('t.createdAt > :interval')
            ->andWhere('t.ip = :ip')
            ->setParameters([
                'interval' => Carbon::now()->subSeconds($this->ipInterval),
                'ip'  => $ipAddress
            ]);

        return new Collection($queryBuilder->getQuery()->getResult());
    }
657219
public function geolocateIPAddress(AddressInterface $address)
    {
        $result = new GeolocationResult();
        try {
            switch ($address->getRangeType()) {
                case IPRangeType::T_PUBLIC:
                    $addressString = (string) $address;
                    $session = $this->app->make('session');
                    $sessionKey = 'ccm/geolocation/' . $this->geolocator->getGeolocatorHandle() . '/' . $this->geolocator->getGeolocatorID() . '/' . md5(serialize($this->geolocator->getGeolocatorConfiguration())) . '/' . $addressString;
                    if ($session->has($sessionKey)) {
                        $result = $session->get($sessionKey);
                    } else {
                        $result = $this->performGeolocation($address);
                        $session->set($sessionKey, $result);
                    }
                    break;
                default:
                    $result->setError(GeolocationResult::ERR_IPNOTPUBLIC);
                    break;
            }
        } catch (Exception $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', $x);
        } catch (Throwable $x) {
            $result->setError(GeolocationResult::ERR_OTHER, '', new Exception($x->getMessage(), $x->getCode()));
        }

        return $result;
    }
352359
public function ifIsIpAddress()
    {
        if ($this->value->isIpAddress()) {
            return $this->value->value();
        }

        $this->paramErrors->append($this->paramName, 'INVALID_IP_ADDRESS');
        return null;
    }
693442
public function locate($ipAddress)
    {
        $response = $this->client->get("json/$ipAddress");

        // Parse body content
        $data = json_decode($response->getBody());

        // Verify response status
        if ($data->status !== 'success') {
            throw new Exception("Request failed ({$data->message})");
        }

        return $this->hydrate([
            'ip'          => $ipAddress,
            'iso_code'    => $data->countryCode,
            'country'     => $data->country,
            'city'        => $data->city,
            'state'       => $data->regionName,
            'state_code'  => $data->region,
            'postal_code' => $data->zip,
            'latitude'    => $data->lat,
            'longitude'   => $data->lon,
            'timezone'    => $data->timezone,
            'continent'   => $this->continents->get($data->countryCode, 'Unknown'),
        ]);
    }
258551
protected function makeFinalResult($ipAddress)
    {
        return $this->target->setResult(
            $this->makeResult(
                false,
                sprintf(
                    $this->target->getErrorMessage(),
                    $this->hosnameAndIp($this->target->hostname, $ipAddress),
                    $this->target->port
                )
            )
        )->getResult();
    }
647747
private function find($ip = null)
    {
        // If IP not set, user remote IP
        $ip = $ip ?: $this->remote_ip;

        // Check cache for location
        if ($this->config('cache', 'none') !== 'none' && $location = $this->getCache()->get($ip)) {
            $location->cached = true;

            return $location;
        }

        // Check if the ip is not local or empty
        if ($this->isValid($ip)) {
            try {
                // Find location
                $location = $this->getService()->locate($ip);

                // Set currency if not already set by the service
                if (!$location->currency) {
                    $location->currency = $this->getCurrency($location->iso_code);
                }

                // Set default
                $location->default = false;

                return $location;
            }
            catch (\Exception $e) {
                if ($this->config('log_failures', true) === true) {
                    $log = new Logger('geoip');
                    $log->pushHandler(new StreamHandler(storage_path('logs/geoip.log'), Logger::ERROR));
                    $log->addError($e);
                }
            }
        }

        return $this->getService()->hydrate($this->default_location);
    }
730375
public static function isTenantServer($ipAddress)
    {
        if (in_array($ipAddress, self::getTenantServerIPAddresses())) {
            return true;
        }
        foreach (self::getTenantServerMasks() as $mask) {
            if (self::checkIPAddressAgainstCIDRMask($ipAddress, $mask)) {
                return true;
            }
        }

        return false;
    }
971298
public static function validateIpAddress($ipAddress) {
        if (strtolower($ipAddress) === 'unknown') {
            return false;
        }

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

        // if the ip is set and not equivalent to 255.255.255.255
        if ($ipAddress !== false && $ipAddress !== -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)
            $ipAddress = sprintf('%u', $ipAddress);
            // do private network range checking
            if ($ipAddress >= 0 && $ipAddress <= 50331647) {
                return false;
            }
            if ($ipAddress >= 167772160 && $ipAddress <= 184549375) {
                return false;
            }
            if ($ipAddress >= 2130706432 && $ipAddress <= 2147483647) {
                return false;
            }
            if ($ipAddress >= 2851995648 && $ipAddress <= 2852061183) {
                return false;
            }
            if ($ipAddress >= 2886729728 && $ipAddress <= 2887778303) {
                return false;
            }
            if ($ipAddress >= 3221225984 && $ipAddress <= 3221226239) {
                return false;
            }
            if ($ipAddress >= 3232235520 && $ipAddress <= 3232301055) {
                return false;
            }
            if ($ipAddress >= 4294967040) {
                return false;
            }
        }
        return true;
    }
687778
public function setIpAddress($ip_address)
    {

        if (!is_null($ip_address) && (!preg_match("/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?$/", $ip_address))) {
            throw new \InvalidArgumentException("invalid value for $ip_address when calling Server., must conform to the pattern /^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))?$/.");
        }

        $this->container['ip_address'] = $ip_address;

        return $this;
    }
281189
public function validateIP($ipAddress = null)
    {
        if ($ipAddress === null) {
            $parsed = parse_url($this->uri);
            $ipAddress = isset($parsed['host']) ? $parsed['host'] : null;
        }
        return (
            filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ||
            filter_var(trim($ipAddress, '[]'), FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)
        );
    }
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
        );
    }
1349627
private static function _remoteIP()
    {
        // Catch all possible hints of the client's IP address, not just REMOTE_ADDR
        foreach (
            array(
                'HTTP_CLIENT_IP',
                'HTTP_X_FORWARDED_FOR',
                'HTTP_X_FORWARDED',
                'HTTP_X_CLUSTER_CLIENT_IP',
                'HTTP_FORWARDED_FOR',
                'HTTP_FORWARDED',
                'REMOTE_ADDR'
            )
            as $key
        ) {
            if (array_key_exists($key, $_SERVER)) {
                foreach (dejoin(',', $_SERVER[$key]) as $ip) {
                    if (filter_var($ip, FILTER_VALIDATE_IP)) {
                        // Return the first one found
                        return $ip;
                    };
                };
            };
        };
        return null;
    }
875290
public static function currentIpAddress() {

    //
    // Just get the headers if we can or else use the SERVER global
    //
    if (function_exists('apache_request_headers')) {
      $headers = apache_request_headers();
    } else {
      $headers = $_SERVER;
    }

    //
    // Get the forwarded IP if it exists
    //
    if (
      array_key_exists('X-Forwarded-For', $headers) &&
      filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
    ) {
      $the_ip = $headers['X-Forwarded-For'];
    }

    elseif (
      array_key_exists('HTTP_X_FORWARDED_FOR', $headers ) &&
      filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
    ) {
      $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
    }

    else {
      $the_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
    }

    return $the_ip;
  }
902523
static public function fromAddress($address)
    {
        if ($address instanceof Address) {
            $addr = $address->toClean();
            $prefix = substr($addr, 0, 1);
        }
        elseif (is_string($address)) {
            $prefix = substr($address, 0, 1);
        }
        else {
            throw new \InvalidArgumentException("Could not identify address format: " . var_export($address, true));
        }

        foreach (self::$networkInfos as $name => $spec) {
            $netChar = $spec['char'];

            if ($prefix == $netChar)
                return $spec["id"];
        }

        throw new \InvalidArgumentException("Could not identify network from provided address: " . var_export($address, true));
    }
967500
public function findByUserId($id, $ipAddress = null)
	{
		return $this->findByUser($this->userProvider->findById($id),$ipAddress);
	}