diff options
author | 2025-05-28 22:05:13 +0100 | |
---|---|---|
committer | 2025-05-28 22:05:13 +0100 | |
commit | e8f2d5181fa9881571e742744edfd0a514009736 (patch) | |
tree | 3101133fb35fc90248fd2504155b8a5c9cc56cf5 | |
parent | Add DMARC struct storage and validation (diff) |
Add utility module for fetching DNS data
-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 |