View Source GeoIP (GeoIP v0.2.8)

Elixir library to lookup the geo location for an IP address or hostname using freegeoip.net

Examples

iex> GeoIP.lookup("google.com")
{:ok,
 %{
  city: "San Francisco",
  country_code: "US",
  country_name: "United States",
  ip: "192.30.253.113",
  latitude: 37.7697,
  longitude: -122.3933,
  metro_code: 807,
  region_code: "CA",
  region_name: "California",
  time_zone: "America/Los_Angeles",
  zip_code: "94107"
  }
}

Summary

Functions

Lookup the location for the given IP address/hostname.

Callback implementation for Application.start/2.

Functions

Lookup the location for the given IP address/hostname.

Args:

  • host - The IP/hostname or Plug.Conn instance to use for the lookup. The IP can be either a string or a tuple.

This function returns {:ok, response} if the lookup is successful, {:error, %GeoIP.Error{reason: reason}} otherwise.

Examples

{:ok, location} = GeoIP.lookup({8, 8, 8, 8})
{:ok, location} = GeoIP.lookup("8.8.8.8")
{:ok, location} = GeoIP.lookup("google.com")
{:ok, location} = GeoIP.lookup(conn)         # A `Plug.Conn` instance

Callback implementation for Application.start/2.