Elixir - Making DNS Queries (Using dig command)

Solution 1:

While you can shell out to dig or other DNS resolving command it is better to use DNS resolving features built in into Erlang:

{:ok, res} = :inet_res.nslookup('google.com', :in, :txt)
txt_rr =
  res
  |> :inet_dns.msg()
  |> Keyword.fetch!(:enlist)
  |> Enum.map(&:inet_dns.rr/1)

Will result with:

[
  [
    domain: 'google.com',
    type: :txt,
    class: :in,
    ttl: 94,
    data: ['globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=']
  ],
  [
    domain: 'google.com',
    type: :txt,
    class: :in,
    ttl: 94,
    data: ['facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95']
  ],
  [
    domain: 'google.com',
    type: :txt,
    class: :in,
    ttl: 94,
    data: ['docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e']
  ],
  [
    domain: 'google.com',
    type: :txt,
    class: :in,
    ttl: 94,
    data: ['docusign=1b0a6754-49b1-4db5-8540-d2c12664b289']
  ],
  [
    domain: 'google.com',
    type: :txt,
    class: :in,
    ttl: 94,
    data: ['v=spf1 include:_spf.google.com ~all']
  ]
]