eXLookupNS - FAQ
Exontrol.COM Software - Frequently Asked Questions - ExLookupNS Component
The control's release notes can be found on our web site, looking for the Release Notes column in the control's main page. Click here for direct link.
The ExLookupDN COM object is a DNS (Domain Name Service) component that can be used for network diagnosing, troubleshooting, and monitoring. In order to be able to use the component all that you need to do is to add a reference to the ExLookupNS library to your project. 

The following sample shows how to find the IP addresses for the microsoft.com host::

    1. Create a new project

    2. Use the Project->References... dialog to select the ExLookupNS Control Library

    3. Add the code shown bellow to Form1

Dim ns As New LookupNS
Debug.Print ns.Query("microsoft.com").Address

The Address property gets all the IP addresses found. The IP addresses are separated by Separator property. Change the Separator property to NULL character to gets only the first address, like in the following sample:

Dim ns As New LookupNS
ns.Separator = Chr(0)
Debug.Print ns.Query("microsoft.com").Address
The Query property of the component retrieves a Message object. When you do a call for any property of the Message object, the components builds and sends the query to the name server. When you do a query using one of the following properties MailInformation, HostInformation, Location, WellKnownService or ZoneOfAuthority, it is recommended to store the object reference for future use ( else a new query is sent to the name server ), like in the following sample:
Dim ns As New LookupNS, soa As ZoneOfAuthority
Set soa = ns.Query("microsoft.com").ZoneOfAuthority
If (ns.LastErrorCode = 0) Then
    Debug.Print "origin: " & soa.PrimaryNameServer
    Debug.Print "mail addr: " & soa.MailboxServerName
    Debug.Print "serial: " + Str(soa.Serial)
    Debug.Print "refresh: " + Str(soa.Refresh) + "(" & Str(soa.Refresh / 60) & "M)"
    Debug.Print "retry: " + Str(soa.Retry) + "(" & Str(soa.Retry / 60) & "M)"
    Debug.Print "expire: " + Str(soa.Expire) + "(" + Str(soa.Expire / 60) & "M)"
    Debug.Print "minimum ttl: " + Str(soa.Minimum) + "(" + Str(soa.Minimum / 60) & "M)"
End If
You have to query the name server using the DomainNamePointer property. Here's the sample:
Dim ns As New LookupNS
Debug.Print ns.Query("").DomainNamePointer
The ExLookupNS component is able to ask the name server for all mail servers for a host. 

For instance the following samples shows how to print the entire list of mail servers:

Dim ns As New LookupNS
Debug.Print ns.Query("microsoft.com").MailExchange

The mail servers are separated by Separator property, and ordered by mail server preference. Fist one is the most preferred. 

The following samples shows how to get only the most preferred mail server:

Dim ns As New LookupNS
ns.Separator = Chr(0)
Debug.Print ns.Query("microsoft.com").MailExchange
The ExLookupNS components has implemented the LOC DNS record resource as described by RFC 1876. The following sample shows how to get the location for yahoo.com:
Dim ns As New LookupNS
Dim loc As Location
Set loc = ns.Query("yahoo.com").Location
Debug.Print "Version:" & loc.Version
Debug.Print "Size:" & Str(loc.Size) & " cm."
Debug.Print "Latitude:" & loc.Latitude
Debug.Print "Longitude:" & loc.Longitude
Debug.Print "Altitude:" & loc.Altitude
The idea is to check the LastErrorCode property. See bellow for all error codes.
Dim ns As New LookupNS, s As String
s = ns.Query("micro4soft.com").Address
If (ns.LastErrorCode = 32003) Then
    Debug.Print "The host does not exist."
End If
The ExLookupNS implements LastError(LastErrorCode) property that gets the description(code) for the last error. So, it is recommended to check the LastError property after a query was sent to the server as bellow sample. The ExLookupNS component handles two kind of errors: WSA ( sockets error ) and NS ( name server ) errors. An WSA error occurs only if the component fails to comunicate with the name server. A NS error occurs only if the name server was unable to answer to the query.

Here's a list of all NS errors:

Code NS Error Description
32001 The name server was unable to process the query.
32002 The name server was unable to process the query due a problem with the name server.
32003 The host does not exist.
32004 The name server does not support the requested kind of query.
32005 The name server refuses to perform the specified operation for policy reasons.

The most frequent error that might appear is 32003 ( The host does not exist.).

In order to find out why my query is empty, you have to check the LastError or LastErrorCode property. If there were no errors ( LastErrorCode = 0 ), that means that the name server was able to send its answers to the client, the name server has not found any answers that match to the query. Here's a sample that shows how to handle an error situation:

Dim ms As String
Dim ns As New LookupNS
ns.Separator = Chr(0)
ms = ns.Query("www.exontrol.com").MailExchange
If (ns.LastErrorCode = 0) Then
    If (ms = "") Then
        Debug.Print "The host exists, but there is no mail server."
        Debug.Print "The primary mail server is: " & ms
    End If
    Debug.Print ns.LastError
End If
By default, the Server property of the component is set to the first local name server found. To change the timeout value use the TimeOut property. If you need an infinite timeout use -1.
General Questions
Copyright 1999-2018 Exontrol. All rights reserved.