The following example uses the DnsQuery object to query microsoft.com for
Address records using fail over DNS servers. aspNetDns has the capability to use
multiple DNS servers for fail over functionality. If a connection to one DNS
server fails, or quits responding, aspNetDns will automatically move to the next
DNS server. In this example we use 3 DNS servers for failover (each DNS server
is separated by a semi-colon): 127.0.0.1;207.46.138.20;143.236.12.13
[C#]
using System;
using aspNetDns;
using aspNetDns.Records;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DnsQuery dns = new DnsQuery( "127.0.0.1;207.46.138.20;143.236.12.13" );
string LookupRecord = "microsoft.com";
ResourceRecord[] records = dns.GetDnsRecords( DnsQueryType.A, LookupRecord );
if( records.Length > 0 )
{
for( int i=0;i<records.Length;i++)
{
Console.WriteLine( "Address Record: " + records[i].AnswerString );
}
}
else
{
Console.WriteLine( "No address records were found.");
}
Console.WriteLine( "done.");
Console.ReadLine();
}
}
}
[VB.NET]
Imports aspNetDns
Imports aspNetDns.Records
Module Module1
Sub Main(ByVal args() As String)
Dim dns As New DnsQuery( "127.0.0.1;207.46.138.20;143.236.12.13" )
Dim LookupRecord As String = "microsoft.com"
Dim records As ResourceRecord() = dns.GetDnsRecords(DnsQueryType.A, LookupRecord)
If records.Length > 0 Then
Dim i As Integer
For i = 0 To records.Length - 1
Console.WriteLine("Address Record: " + records(i).AnswerString)
Next i
Else
Console.WriteLine("No address records were found.")
End If
Console.WriteLine("done.")
Console.ReadLine()
End Sub 'Main
End Module