ipdb_decoder v0.0.2 IPDBDecoder View Source

IPIP.net ipdb file format decoder.

Usage

To prepare lookups in a given database, you need parse first and hold the results for later usage:

iex(1)> {:ok, database} = IPDBDecoder.parse_database_file("/path/to/ipipfree.ipdb")

Using the returned database contents, you could start looking up

iex(3)> IPDBDecoder.lookup(database, "127.0.0.1")
{:ok, %{}}

Link to this section Summary

Link to this section Types

Link to this type

decode_options() View Source
decode_options() :: map()

Link to this type

decoded_value() View Source
decoded_value() ::
  :cache | :end | binary() | boolean() | list() | map() | number()

Link to this type

lookup_result() View Source
lookup_result() :: {:ok, decoded_value()} | {:error, term()}

Link to this type

parse_result() View Source
parse_result() :: {:ok, IPDBDecoder.Database.t()} | {:error, term()}

Link to this section Functions

Link to this function

lookup(parse_result, ipstring, options \\ []) View Source
lookup(
  IPDBDecoder.Database.t(),
  String.t() | :inet.ip_address(),
  decode_options()
) :: lookup_result()

Link to this function

parse_database(content) View Source
parse_database(binary()) :: parse_result()

Link to this function

parse_database_file(path) View Source
parse_database_file(String.t()) :: parse_result()

Link to this function

pipe_lookup(parse_result, ip, options \\ []) View Source

Utility method to pipe parse_database/1 directly to lookup/2.

Usage

Depending on how you handle the parsed database contents you may want to pass the results directly to the lookup.

iex> "/path/to/database.ipdb"
...> |> File.read!()
...> |> IPDBDecoder.parse_database()
...> |> IPDBDecoder.pipe_lookup({127, 0, 0, 1})
{:ok, %{...}}