ActiveXperts Network Component


DNS NsLookup Sample Source Code in ASP

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.

Network Component can be well integrated into any development platform that supports ActiveX objects.

The Domain Name System (DNS) is the method by which Internet addresses in mnemonic form - such as - are converted into the equivalent numeric IP address such as To the user and application process this translation is a service provided either by the local host or from a remote host via the Internet. The DNS server (or resolver) may communicate with other Internet DNS servers if it cannot translate the address itself. DNS names are constructed hierarchically. The highest level of the hierarchy is the last component or label of the DNS address. Labels can be up to 63 characters long and are not case sensitive. A maximum length of 255 characters is allowed. Labels must start with a letter and can only consist of letters, digits and hyphens.

Nslookup is a popular program for UNIX, Linux and Windows to query Internet domain name servers. It allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain.

Step 1: Download and install Network Component

Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Web Site

First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.

From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':


(Click on the picture to enlarge)

The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:

  • Description - a friendly description of the new site;
  • IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
  • Path - select the directory that will store the ASP file(s);
  • Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';

You're now able to write an ASP script to use IP protocols with Network Component.

Step 3: Create the from

First of all we need to create a form in HTML to get the login information for the ftp server. All we actually need is:

  • The log-in name.
  • The password.
  • The server we want to connect to.
  • And the directory we're going to list.

In this sample all we're going to do is create a ASP file that is able to list files and directories in a directory. Using Network Component it is easy to create a page that makes you able to upload and to download files.

You can create a form that looks like this:

(Click on the picture to enlarge)

Step 4:Create ActiveXperts Network Component objects in ASP

Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. On top of the ASP code, insert the following lines to declare and create the Dns object:

<object runat="server" progid="AxNetwork.DnsServer"   id="objDnsServer"></object>
<object runat="server" progid="AxNetwork.ASConstants" id="objConstants"></object>

Step 5: Test a small piece of ASP

Now, test if your new web site is working well with ActiveXperts Network Component using your browser. If you are using Microsoft Internet Explorer, it is recommended to disable friendly error message because this default setting doesn't show any ASP error message, making it hard to debug if there are any problems:

  • Choose' Internet Options' from the 'Tools' menu;
  • Select the 'Advanced' tab;
  • In the 'Browsing' folder, de-select the 'Show friendly HTTP error messages' option;
  • Click 'OK' to close the dialog.

Now, use the following piece of code in your DEFAULT.ASP page and test it into your favourite browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="" >
    <title>ActiveXperts Network Component ASP Demo</title>
    <object runat="server" progid="AxNetwork.DnsServer" id="objDnsServer"></object>
    <object runat="server" progid="AxNetwork.Constants" id="objConstants"></object>

    <title>Network Component Demo</title>
     Network Component version: <% = objSmtp.Version %>
     <br />
     Network Component License Status: <% = objSmtp.LicenseStatus %>

Appendix: Full source code

<object runat="server" progid="AxNetwork.DnsServer" id="objDnsServer"> </object>
<object runat="server" progid="AxNetwork.NwConstants" id="objConstants"> </object>

' HTML-CSS layout includes below, no code there!
<!-- #include file="css/Header.html" -->
<!-- #include file="css/Menu.html" -->

  ' A license key is required to unlock this component after the trial period has expired.
  ' Call 'Activate' with a valid license key as its first parameter. Second parameter determines whether to save the license key permanently 
  ' to the registry (True, so you need to call Activate only once), or not to store the key permanently (False, so you need to call Activate
  ' every time the component is created). For details, see manual, chapter "Product Activation".
  ' objDnsServer.Activate "XXXXX-XXXXX-XXXXX", False    

  Dim numLastError, strLastError, objDnsRecord, strResponse
  Set fso = CreateObject("Scripting.FileSystemObject")
  strLogfile = fso.GetSpecialFolder(2) & "\Dns.log"

  strLastError = ""
  strResponse  = ""

  If( Request( "btnSubmit" ) <> "" ) Then
    objDnsServer.LogFile       = Request( "txtLogFile" )    ' Optional: set LogFile property for troubleshooting purposes

    objDnsServer.Server        = Request( "txtDnsServer" )
    objDnsServer.Lookup Request( "txtHost" ), objConstants.nwDNS_TYPE_ANY
    numLastError               =  objDnsServer.LastError

    If( numLastError = 0 ) Then
       Set objDnsRecord = objDnsServer.GetFirstRecord
       strResponse = strResponse & GetDnsRecordInfo( objDnsRecord )
     End If

    strLastError =  numLastError & ": " & objDnsServer.GetErrorDescription( numLastError )  
  End If

<div class="ax_container">
  <h1>ActiveXperts Network Component ASP Sample - DNS</h1>
  <form action="dns.asp" method="post">
    <h3>Module [<% = objDnsServer.Module %>]; Build [<% = objDnsServer.Build %>]</h3>
    <!-- DNS Server -->
    <label for="DnsServer">DNS Server:</label>
      <input type="text" name="txtDnsServer" value="<% If Request( "txtDnsServer" ) = "" Then %><% Else %><% = Request( "txtDnsServer" ) %><% End If %>" />
    <!-- Host -->
    <label for="Host">Host:</label>
      <input type="text" name="txtHost" value="<% If Request( "txtHost" ) = "" Then %><% Else %><% = Request( "txtHost" ) %><% End If %>" />   
    <!-- Submit Button -->
    <div class="ax_clearLabel"></div>
      <input type="submit" value="Lookup" name="btnSubmit">
    <!-- Empty Row -->
    <div class="ax_clearRow"></div>
    <!-- Logfile -->
    <label for="Logfile">Logfile:</label>
      <input type="text" id="LogFile" name="txtLogFile" class="ax_FullWidth" value="<% = strLogfile %>" />
    <!-- Result -->
    <label for="Result">Result:</label>
      <input type="text" id="Result" name="txtResult" class="ax_FullWidth" style="font-weight: bold;" value="<% = strLastError %>" />
    <!-- Query Results: -->
    <label for="QueryResult">Query results:</label>
      <textarea class="ax_FullWidth" style="Height:200px;" name="txtResponse"><% = strResponse %></textarea>
    <br />
    <br />
    This sample is based on ActiveXperts Network Component, an <a href="" target="_blank">ActiveXperts Software</a> product.<br />
    <a href="Default.asp">Back to main page</a>
</div><!-- /container -->
' HTML-CSS layout include below, no code there!
<!-- #include file="css/Footer.html" -->

<% Function GetDnsRecordInfo( objDnsRecord )

    Dim strInfo, numType

    numType = objDnsRecord.Type

    Select Case numType 
      Case objConstants.nwDNS_TYPE_A
        strInfo = strInfo & "Type             : A" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "IPv4 Address     : " & objDnsRecord.Address & vbCrLf
      Case objConstants.nwDNS_TYPE_AAAA
        strInfo = strInfo & "Type             : AAAA" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "IPv6 Address     : " & objDnsRecord.Address & vbCrLf
      Case objConstants.nwDNS_TYPE_CNAME
        strInfo = strInfo & "Type             : CNAME" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "Alias            : " & objDnsRecord.Address & vbCrLf
      Case objConstants.nwDNS_TYPE_MX 
        strInfo = strInfo & "Type             : MX" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "Preference       : " & objDnsRecord.Preference & vbCrLf
        strInfo = strInfo & "Mail Exchange    : " & objDnsRecord.MailExchange & vbCrLf
      Case objConstants.nwDNS_TYPE_NS
        strInfo = strInfo & "Type             : NS" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "Name Server      : " & objDnsRecord.NameServer & vbCrLf
      Case objConstants.nwDNS_TYPE_PTR
        strInfo = strInfo & "Type             : PTR" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "Host             : " & objDnsRecord.Address & vbCrLf
      Case objConstants.nwDNS_TYPE_SOA
        strInfo = strInfo & "Type             : SOA" & vbCrLf
        strInfo = strInfo & "Name             : " & objDnsRecord.Name & vbCrLf
        strInfo = strInfo & "Name Server      : " & objDnsRecord.NameServer & vbCrLf
        strInfo = strInfo & "MailBox          : " & objDnsRecord.MailBox & vbCrLf
        strInfo = strInfo & "Serial           : " & objDnsRecord.SerialNumber & vbCrLf
        strInfo = strInfo & "Refresh          : " & objDnsRecord.RefreshInterval & vbCrLf
        strInfo = strInfo & "Retry Interval   : " & objDnsRecord.RetryInterval & vbCrLf
        strInfo = strInfo & "Expiration Limit : " & objDnsRecord.ExpirationLimit & vbCrLf
        strInfo = strInfo & "Minimum TTL      : " & objDnsRecord.MinimumTTL & vbCrLf
    End Select
    strInfo = strInfo & "TTL              : " & objDnsRecord.TTL & vbCrLf & vbCrLf

    GetDnsRecordInfo = strInfo
   End Function

You can download the complete sample on our FTP site There are many other working Network Component scripts on our site and shipped with the product.