Search code examples
dnsttl

Obtaining ttl value for DNS records


Iam writing a program to gather data on ttl of various DNS records.I could get it for SOA. Can anyone say how to obtain ttl value for MX , A records ?


Solution

  • Edit: You'll have to query the DNS for MX or A records

    Your complete response should contain:

    1. a DNS header section
    2. a question section in which the sections are sent back to you (the questions number is found in the dns header).
    3. an answer section in which the answers will be found (similar to the question section, the number of the answers can also be found in the dns header)

    Now, each answer will have its own header, that has the following form:

    type     - 16 bits
    class    - 16 bits
    ttl      - 32 bits
    rdlength - 16 bits
    

    the content after the header depends on the type of response, but the ttl is in the header.

    Here's some reference: http://www.ietf.org/rfc/rfc1035.txt