Code Samples
The product includes numerous VB.NET, C# and ASP.NET sample applications. All
samples include complete source code. For more detailed sample code please
refer to the sample applications.
DNS Forward Lookup
Listing 1 demonstrates using the synchronous Lookup
method to perform a DNS forward lookup (resolving a host name
to an IP address).
Dim dnsClient as New DnsClient()
Dim ipAddresses As IPAddress()
ipAddresses = dnsClient.Lookup("www.componentspace.com")
For Each ipAddress As IPAddress In ipAddresses
' Process the IP address
Next
|
Listing 1 DNS forward lookup
DNS Reverse Lookup
Listing 2 demonstrates using the synchronous ReverseLookup
method to perform a DNS reverse lookup (resolving an IP address
to a host name).
Dim dnsClient as New DnsClient()
Dim hostNames As String()
hostNames = dnsClient.ReverseLookup(IPAddress.Parse("64.26.22.64"))
For Each hostName As String In hostNames
' Process the host name
Next
|
Listing 2 DNS reverse lookup
Querying a DNS Server
Listing 3 demonstrates using the synchronous Send
and Receive methods to communicate with a DNS server.
Request construction and accessing the details in the response message
is made easy by using the DnsMessage class.
' Lookup a local DNS server to query
Dim dnsServers As IPAddress()
dnsServers = dnsClient.DnsServerList
Dim dnsClient as New DnsClient(dnsServers(0))
' Construct the DNS request message and send it
Dim request As New DnsMessage()
request.OpCode = CInt(dnsMessage.OpCodes.Query)
request.RecursionDesired = True
request.DnsQuestions.Add(New DnsQuestion(textBoxDomainName.Text, _
Convert.ToUInt16(queryTypeMap(comboBoxQueryType.Text)), _
Convert.ToUInt16(DnsQuestion.QClasses.IN)))
dnsClient.Send(request)
' Receive the response
Dim response As DnsMessage
response = dnsClient.Receive()
' Process the response
|
Listing 3 Querying a DNS server
|