How to get mx records for a dns name with System.Net.DNS?

Answer

It's available from NuGet:

PM> Install-Package ARSoft.Tools.Net

Import the namespace:

using ARSoft.Tools.Net.Dns;

Then making a synchronous lookup is as simple as:

var response = DnsClient.Default.Resolve("gmail.com", RecordType.Mx);
var records = response.AnswerRecords.OfType<MxRecord>();
foreach (var record in records) {
    Console.WriteLine(record.ExchangeDomainName);
}

Which gives us the output:

alt3.gmail-smtp-in.l.google.com
alt4.gmail-smtp-in.l.google.com
gmail-smtp-in.l.google.com
alt1.gmail-smtp-in.l.google.com
alt2.gmail-smtp-in.l.google.com

All dns Questions

Ask your interview questions on dns

Write Your comment or Questions if you want the answers on dns from dns Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---