FreeGeoIP v0.0.5 FreeGeoIP.Search View Source

This module includes the basic search function to get geo information about a specified IP.

Link to this section Summary

Functions

Performs a IP search

Link to this section Functions

Link to this function search(ip, locale \\ nil) View Source

Performs a IP search.

{:ok, result} = FreeGeoIP.search(ip)

Arguments

  • ip: can be either a stinrg or a tuple representing an IPv4 ip format
  • locale: (optional) localize the geolocation data. You can use ISO 639-1 code or any string valid for a Accept-language HTTP header specification](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)

Sample result

%{
  "city" => "San Francisco",
  "country_code" => "US",
  "country_name" => "United States",
  "ip" => "192.30.252.128",
  "latitude" => 37.7697,
  "longitude" => -122.3933,
  "metro_code" => 807,
  "region_code" => "CA",
  "region_name" => "California",
  "time_zone" => "America/Los_Angeles",
  "zip_code" => "94107"
}

Errors:

The errors will have the following format:

%{:error, %{reason: reason, error: error_message}}

reason can be one of the following:

  • :auth_failed: the server is protected with basic authentication and you have passed wrong credentials (see below for authentication)
  • :process_timeout: the server responded, but internally caused a timeout
  • :timeout: server did not respond in a few seconds
  • Any other reason given by the HTTPoison.Error
  • :incorrect_ip_range: incorrect IP provided (like 500.23.1100.32)
  • :incorrect_ip_format: specified IP format not supported. Use only string or tuple.