Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nazipov/ip2location-elixir
An Elixir library for the IP2Location database
https://github.com/nazipov/ip2location-elixir
elixir-library ip2location ip2location-database
Last synced: about 1 month ago
JSON representation
An Elixir library for the IP2Location database
- Host: GitHub
- URL: https://github.com/nazipov/ip2location-elixir
- Owner: nazipov
- License: lgpl-3.0
- Created: 2016-03-24T16:21:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-19T14:55:28.000Z (about 7 years ago)
- Last Synced: 2024-10-03T10:47:42.239Z (2 months ago)
- Topics: elixir-library, ip2location, ip2location-database
- Language: Elixir
- Homepage:
- Size: 14.6 KB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.TXT
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - An Elixir library for IP2Location database. (Geolocation)
- fucking-awesome-elixir - ip2location - An Elixir library for IP2Location database. (Geolocation)
- awesome-elixir - ip2location - An Elixir library for IP2Location database. (Geolocation)
README
# IP2Location
[![Build Status](https://travis-ci.org/nazipov/ip2location-elixir.svg?branch=master)](https://travis-ci.org/nazipov/ip2location-elixir)
[![Hex pm](https://img.shields.io/hexpm/v/ip2location.svg?style=flat)](https://hex.pm/packages/ip2location)Elixir library for the IP2Location database. Supports IPv4 and IPv6.
# Installation
Add IP2Location as a dependency to your project's `mix.exs`:
```elixir
def application do
[applications: [:ip2location]]
enddefp deps do
[{:ip2location, github: "nazipov/ip2location-elixir"}]
end
```and then run `$ mix deps.get`
# Configuration
Add the path of the IP2Location database to your project's configuration:
```elixir
use Mix.Configdatabase_file =
[ __DIR__, "../data/sample-ipv6-db24.bin" ]
|> Path.join()
|> Path.expand()config :ip2location,
database: database_file,
pool: [ size: 5, max_overflow: 10 ]
```# Usage
```elixir
iex(1)> IP2Location.lookup("8.8.8.8")
%IP2Location.Result{ ... }
iex(1)> IP2Location.lookup("2001:4860:4860::8888")
%IP2Location.Result{ ... }
```# Benchmarking
```elixir
iex(1)> :timer.tc(fn -> IP2Location.lookup("8.8.8.8") end )
{150, %IP2Location.Result{ ... }}
iex(2)> :timer.tc(fn -> IP2Location.lookup("2001:4860:4860::8888") end )
{152, %IP2Location.Result{ ... }}
```# Sample BIN Databases
* Download free IP2Location LITE databases at [http://lite.ip2location.com](http://lite.ip2location.com)
* Download IP2Location sample databases at [http://www.ip2location.com/developers](http://www.ip2location.com/developers)# License
[GNU LGPLv3](http://www.gnu.org/licenses/lgpl-3.0.html)