diff options
-rw-r--r-- | lib/dns.ex | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/dns.ex b/lib/dns.ex new file mode 100644 index 0000000..d5dbcec --- /dev/null +++ b/lib/dns.ex @@ -0,0 +1,20 @@ +defmodule Lithium.DNS do + @moduledoc """ + DNS query module. + + Some query magic is performed to do things like joining TXT records together. + """ + + @spec fetch_txt(String.t()) :: {:ok, [String.t()]} | {:error, any()} + def fetch_txt(name) do + case :inet_res.getbyname(String.to_charlist(name), :txt) do + {:ok, {:hostent, _domain, _aliases, :txt, _length, records}} -> + records + |> Enum.map(&List.to_string/1) + |> then(&{:ok, &1}) + + {:error, reason} -> + {:error, reason} + end + end +end |