DNS FeaturesDNS operations are used by ActiveUp.MailSystem for direct send and anti-spam features. Rather than encapsulate the logic, we decided to make this available as public classes available to the customer. The following features cover almost all your DNS needs:
Support for individual queries of all type
Requesting the IP address and related information about a specific DNS entry type of a specific domain name can be handled by this code:
Show C# code
DnsQuery query = new DnsQuery("ns1.example.com"); query.Domain = "example.com"; DnsAnswer result = query.QueryServer(RecordType.A); if (result == null || result.Answers.Count == 0) { Console.WriteLine("No A record available for this domain"); } else { Console.WriteLine("IP Address: {0}", result.Answers[0].Data.ToIPAddress().ToString()); }
Get mail exchange (MX) records of an DNS server
You may need to specifically receive the list of mail exchange servers for the specified domain. Here is the implementation:
Show C# code
DnsQuery query = new DnsQuery("ns1.example.com"); query.Domain = "example.com"; DnsAnswer result = query.QueryServer(RecordType.A); if (result == null || result.Answers.Count == 0) { Console.WriteLine("No MX record available for this domain"); } else { foreach(MXRecord record in answer.Answers) { Console.WriteLine("Host: {0} - Preference: {1}", record.Domain, record.Preference); } }
Get all records from a DNS server
If you want to receive the whole DNS entries for a domain name, this can be handled by this query:
Show C# code
DnsQuery query = new DnsQuery("ns1.example.com"); query.Domain = "example.com"; DnsAnswer result = query.QueryServer(RecordType.All); if (result == null || result.Answers.Count == 0) { Console.WriteLine("No DNS record available for this domain"); } else { foreach(DnsAnswer record in answer.Answers) { Console.WriteLine("{0}", record.Data.ToString()); } }
|