{"id":13508240,"url":"https://github.com/navinpeiris/geoip","last_synced_at":"2025-04-05T02:12:24.831Z","repository":{"id":10862985,"uuid":"67279223","full_name":"navinpeiris/geoip","owner":"navinpeiris","description":"Elixir library to find geo location information given an IP address, hostname or Plug.Conn","archived":false,"fork":false,"pushed_at":"2023-11-01T16:59:11.000Z","size":311,"stargazers_count":121,"open_issues_count":7,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T01:15:11.457Z","etag":null,"topics":["elixir","freegeoip","geolocation","phoenix"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/navinpeiris.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-03T08:16:54.000Z","updated_at":"2025-03-08T12:25:55.000Z","dependencies_parsed_at":"2024-01-05T21:56:03.501Z","dependency_job_id":"b8576875-13a0-409d-a54c-8494b3598bda","html_url":"https://github.com/navinpeiris/geoip","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navinpeiris%2Fgeoip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navinpeiris%2Fgeoip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navinpeiris%2Fgeoip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navinpeiris%2Fgeoip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/navinpeiris","download_url":"https://codeload.github.com/navinpeiris/geoip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","freegeoip","geolocation","phoenix"],"created_at":"2024-08-01T02:00:50.225Z","updated_at":"2025-04-05T02:12:24.808Z","avatar_url":"https://github.com/navinpeiris.png","language":"Elixir","funding_links":[],"categories":["Geolocation"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"assets/verticalversion.png\" alt=\"geoip\" height=\"200px\"\u003e\u003c/p\u003e\n\n# GeoIP\n\n[![Build Status](https://travis-ci.org/navinpeiris/geoip.svg?branch=master)](https://travis-ci.org/navinpeiris/geoip)\n[![Module Version](https://img.shields.io/hexpm/v/geoip.svg)](https://hex.pm/packages/geoip)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/geoip/)\n[![Total Download](https://img.shields.io/hexpm/dt/geoip.svg)](https://hex.pm/packages/geoip)\n[![License](https://img.shields.io/hexpm/l/geoip.svg)](https://github.com/navinpeiris/geoip/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/navinpeiris/geoip.svg)](https://github.com/navinpeiris/geoip/commits/master)\n\nElixir library to lookup the geographic location for a given IP address, hostname, or `Plug.Conn`.\n\nThe returned results are cached for an hour by default so that we don't hit the service unnecessarily, but this is configurable can be disabled using the config options (see below).\n\n## Installation\n\nAdd `:geoip` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:geoip, \"~\u003e 0.2\"}\n  ]\nend\n```\n\nUpdate your mix dependencies:\n\n```elixir\nmix deps.get\n```\n\n## Configuration\n\n### Provider\n\nThe provider must be explicitly specified along with any required attributes as per examples below.\n\n#### freegeoip\n\nThe free host that was available at `freegeoip.net` and the corresponding source repository at\n[fiorix/freegeoip](https://github.com/fiorix/freegeoip) was deprecated in the middle of 2018, but\nit still allows you to launch your own instance if you wish.\n\n```elixir\nconfig :geoip, provider: :freegeoip, url: \"https://geoip.example.com\"\n```\n\n#### ipstack\n\n[ipstack](https://ipstack.com) provides a free tier although it requires you to sign up and get an api key first.\n\nNOTE: The free tier does not allow https access so you _must_ specify `use_https: false` below.\n\n```elixir\nconfig :geoip, provider: :ipstack, api_key: \"your-api-key\"\n```\n\n#### ipinfo\n\n[ipinfo](https://ipinfo.io) does not unfortunately support lookup by hostname (only ip address), therefore the above examples where a hostname is used will return an error.\n\n```elixir\nconfig :geoip, provider: :ipinfo, api_key: \"your-api-key\"\n```\n\n#### IP2Location.io\n\n[IP2Location.io](https://ip2location.io) does not support lookup by hostname (only ip address), therefore the above examples where a hostname is used will return an error.\n\nNOTE: Translation for certain columns is available for Plus and Security plan. You can visit the Parameters section in [https://www.ip2location.io/ip2location-documentation](https://www.ip2location.io/ip2location-documentation) for more information\n\n```elixir\nconfig :geoip, provider: :ip2locationio, api_key: \"your-api-key\"\n```\n\n#### test\n\nProvides an easy way to provide mock lookup data in test environments.\n\nThe `test_results` param is a map of host to lookup results that should be returned. If the ip/host looked up is not found in this map, then the results provided by the `default_test_result` param is provided.\n\n```elixir\nconfig :geoip,\n  provider: :test,\n  test_results: %{ # optional\n   \"host.1\" =\u003e %{\n     ip: \"123.123.123.123\",\n     # ......\n   },\n   \"host.2\" =\u003e %{\n     ip: \"1.1.1.1\",\n     # ......\n   },\n  },\n  default_test_result: %{ # optional\n   ip: \"192.168.3.3\",\n   # ......\n  }\n```\n\n### Caching\n\nBy default, the location results returned by the freegeoip server is cached for an hour. We can disable the cache by:\n\n```elixir\nconfig :geoip, cache: false\n```\n\nOr to change the time limit of cached results:\n\n```elixir\nconfig :geoip, cache_ttl_secs: 1800 # 30 mins\n```\n\n### Extra parameters\n\nYou can add extra query parameters to geoip service requests via `:extra_params` config option:\n\n```elixir\nconfig :geoip, extra_params: [language: \"RU\"]\n```\n\n## Usage\n\nYou can pass in an IP address (as a string or a struct), hostname or a `Plug.Conn` struct to be looked up.\n\n```elixir\nGeoIP.lookup(\"google.com\")\n#=\u003e {:ok, %{city: \"Mountain View\", country_code: \"US\", country_name: \"United States\", ip: \"172.217.4.78\", latitude: 37.4192, longitude: -122.0574, metro_code: 807, region_code: \"CA\", region_name: \"California\", time_zone: \"America/Los_Angeles\", zip_code: \"94043\"}}\n\n# Other examples:\nGeoIP.lookup(\"8.8.8.8\")\nGeoIP.lookup({8, 8, 8, 8})\nGeoIP.lookup(conn)\n```\n\nThis returns `{:ok, response}` if the lookup is successful, `{:error, %GeoIP.Error{reason: reason}}` otherwise.\n\n## Testing\n\nPlease see the `test` provider above.\n\n## Determining your `remote_ip` when behind a proxy\n\nIf your application is running behind a proxy, we recommend using [ajvondrak/remote_ip](https://github.com/ajvondrak/remote_ip) or something similar to override the `remote_ip` field of `Plug.Conn`. Due to the various different ways of determining the applications remote ip depending on your deployment environment, we leave this up to you to configure as appropriate.\n\n## GeoIP logo\n\nSpecial thanks to [@batarian71](https://github.com/batarian71) for designing and providing this project with an awesome logo\n\n## Related Packages\n\n* https://github.com/elixir-geolix/geolix If you want to use the [MaxMind files directly](https://github.com/navinpeiris/geoip/issues/1)\n* https://github.com/knrz/geocoder\n* https://github.com/amotion-city/lib_lat_lon\n\n## Copyright and License\n\nCopyright (c) 2016 Navin Peiris\n\nThis work is free. You can redistribute it and/or modify it under the\nterms of the MIT License. See the [LICENSE.md](./LICENSE.md) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnavinpeiris%2Fgeoip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnavinpeiris%2Fgeoip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnavinpeiris%2Fgeoip/lists"}