Anyone know how to find the TTL for a DNS record with :inet?

I’m learning my way around :inet and :inet_res to perform DNS lookups but the documentation is a little confusing. Getting the value for the records themselves is straightforward enough, but I can’t figure out how to find the TTL values for each of the records.

Anybody ever figure this out?

1 Like

:inet_res.resolve should give you the TTL for each record it returns.
For example, in:

iex(1)> :inet_res.resolve('elixirforum.com', :in, :a)

{:ok,
 {:dns_rec, {:dns_header, 1, true, :query, false, false, true, true, false, 0},
  [{:dns_query, 'elixirforum.com', :a, :in}],
  [
    {:dns_rr, 'elixirforum.com', :a, :in, 0, 28537, {78, 46, 110, 60},
     :undefined, [], false}
  ], [], []}}

28537 is the TTL

2 Likes

Thank you! I was trying to figure it out with lookup.

1 Like