DNS (dns v2.4.0) View Source

Link to this section Summary

Functions

Queries the DNS server and returns the result.

Link to this section Types

Specs

nameserver() :: {String.t(), port :: 1..65535}

Specs

res_option() ::
  :inet_res.res_option()
  | {:alt_nameservers, [nameserver()]}
  | {:nameservers, [nameserver()]}

Specs

rr_type() ::
  :a
  | :aaaa
  | :caa
  | :cname
  | :gid
  | :hinfo
  | :ns
  | :mb
  | :md
  | :mg
  | :mf
  | :minfo
  | :mx
  | :naptr
  | :null
  | :ptr
  | :soa
  | :spf
  | :srv
  | :txt
  | :uid
  | :uinfo
  | :unspec
  | :uri
  | :wks

Link to this section Functions

Link to this function

query(name, type \\ :a, opts \\ [], timeout \\ :infinity)

View Source

Specs

query(String.t(), rr_type(), [res_option()], timeout()) ::
  {:ok, DNS.Record.t()} | {:error, :inet_res.res_error()}

Queries the DNS server and returns the result.

Examples

Queries for A records:

iex> DNS.query("tungdao.com")

Queries for the MX records:

iex> DNS.query("tungdao.com", :mx)

Queries for A records, using OpenDNS:

iex> DNS.query("tungdao.com", :a, nameservers: [{"8.8.4.4", 53}])

Queries for A records, using OpenDNS, with TCP:

iex> DNS.query("tungdao.com", :a, nameservers: [{"8.8.4.4", 53}], usevc: true)
Link to this function

resolve(domain, type \\ :a, opts \\ [], timeout \\ :infinity)

View Source

Specs

resolve(String.t(), rr_type(), [res_option()], timeout()) ::
  {:ok, list()} | {:error, :inet_res.res_error()}

Resolves the answer for a DNS query.

Examples

iex> DNS.resolve("tungdao.com")
{:ok, [{1, 1, 1, 1}]}

iex> DNS.resolve("tungdao.com", :txt)
{:ok, [['v=spf1 a mx ~all']]}

iex> DNS.resolve("tungdao.com", :a, nameservers: [{"8.8.4.4", 53}])
{:ok, [{1, 1, 1, 1}]}

iex> DNS.resolve("tungdao.com", :a, usevc: true)
{:ok, [{1, 1, 1, 1}]}