You are here

public function Reader::get in Smart IP 6.2

Same name and namespace in other branches
  1. 7.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::get()

Looks up the <code>address</code> in the MaxMind DB.

Parameters

string $ipAddress: the IP address to look up.

Return value

array the record for the IP address.

Throws

\BadMethodCallException if this method is called on a closed database.

\InvalidArgumentException if something other than a single IP address is passed to the method.

InvalidDatabaseException if the database is invalid or there is an error reading from it.

File

includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php, line 85

Class

Reader
Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the <code>get</code> method.

Namespace

MaxMind\Db

Code

public function get($ipAddress) {
  if (func_num_args() != 1) {
    throw new \InvalidArgumentException('Method takes exactly one argument.');
  }
  if (!is_resource($this->fileHandle)) {
    throw new \BadMethodCallException('Attempt to read from a closed MaxMind DB.');
  }
  if (!filter_var($ipAddress, FILTER_VALIDATE_IP)) {
    throw new \InvalidArgumentException("The value \"{$ipAddress}\" is not a valid IP address.");
  }
  if ($this->metadata->ipVersion == 4 && strrpos($ipAddress, ':')) {
    throw new \InvalidArgumentException("Error looking up {$ipAddress}. You attempted to look up an" . " IPv6 address in an IPv4-only database.");
  }
  $pointer = $this
    ->findAddressInTree($ipAddress);
  if ($pointer == 0) {
    return null;
  }
  return $this
    ->resolveDataPointer($pointer);
}