This project has moved. For the latest updates, please go here.

Read a MX record for domain

Start a new Visual Studio project (i.e. Console Application) and add the reference DNS.dll (if you're using .NET Micro Framework use MicroDNS.dll instead).

Next you have to create a question. In our sample we want to query the MX record of domain

Question q = new Question("", DnsType.MX, DnsClass.IN);

The DnsResolver needs a DNS server. If you're not using the library within .NET Micro Framework you can use the .LoadNetworkConfiguration method:

DnsResolver dns = new DnsResolver();

Using .NET Micro Framework you should specifiy the DNS server with the constructor of the DnsResolver:

DnsResolver dns = new DnsResolver("dns.local");

To get the MX record IP address you could now read the property from the DnsResponse:

DnsResponse res = dns.Resolve(q);
Console.WriteLine((res.Answers0 as MXRecord).ToString());

Last edited Feb 16, 2009 at 10:30 AM by interactive, version 1


No comments yet.