tags:

views:

142

answers:

2

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 ?

A: 

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      - 16 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

A: 

If you're working in .NET, there is a fairly good DNS library on CodeProject.

You should be able to use it like this:

IPAddress dnsServerAddress = IPAddress.Parse("208.67.222.222");

Request request = new Request();
request.AddQuestion(new Question("microsoft.com", DnsType.ANAME, DnsClass.IN));

Response response = Resolver.Lookup(request, dnsServerAddress);

foreach (Answer answer in response.Answers)
{
    Console.WriteLine("{0}: ttl {1}", 
        ((ANameRecord)answer.Record).IPAddress, answer.Ttl);
}
Richard Beier