Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
Download Manual  (505 KB - .htm file)
DNS NsLookup using VBScript
The Domain Name System (DNS) is the method by which Internet addresses in mnemonic form - such as www.activexperts.com - are converted into the equivalent numeric IP address such as 212.97.55.136. 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.
ActiveSocket provides an easy-to-use development/scripting interface to use the same operations as NsLookup, through the DnsServer class.
By using ActiveSocket, you can very easily create or enhance Windows applications/scripts with DNS lookup features.
ActiveSocket features the following: ICMP, HTTP and HTTPs (supporting for proxy servers, secure web sites), FTP, DNS, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets, WOL (Wake-On-LAN), and more.
Step 1: Download and install the ActiveSocket Toolkit
Download ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 2: Create a new script
Create a new script using your favorite editor.
You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced script to communicate using the ActiveSocket Toolkit.
Step 3: Create the ActiveSocket object in VBScript
Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:
Option Explicit
This statement requires that all variable names be defined (with the Dim statement),
to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.
Now, declare the ActiveSocket object(s):
Dim objDnsServer
Create the ActiveSocket object(s) like this:
Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" )
Now, add the following lines to the file to have your fist ActiveSocket VBScript program:
WScript.Echo "Version: " & objDnsServer.Version
WScript.Echo "Expiration Date: " & objDnsServer.ExpirationDate
Step 4: Execute a DNS lookup query
You can now connect to a (remote) DNS server and execute a query.
The following VBScript code shows how to loolup a hostname (A-record) and print its IP address:
Option Explicit
Dim objDnsServer, objDnsRecord, objConstants
Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")
objDnsServer.Server = "ns1.interstroom.nl"
objDnsServer.Lookup "www.activexperts.com", objConstants.asDNS_TYPE_ANY
If ( objDnsServer.LastError <> 0 ) Then
WScript.Echo "ERROR #" & objDnsServer.LastError & " (" & objDnsServer.GetErrorDescription (objDnsServer.LastError ) & ")"
WScript.Quit
End If
If ( objDnsServer.IsAuthoritative = True ) Then
WScript.Echo "Server is an authority for this domain"
Else
WScript.Echo "Server is not an authority for this domain"
End If
WScript.Echo
Set objDnsRecord = objDnsServer.GetFirstRecord
On Error Resume Next
While ( objDnsServer.LastError = 0 )
Select Case objDnsRecord.Type
Case objConstants.asDNS_TYPE_A
WScript.Echo "Type : A"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "IPv4 Address : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_AAAA
WScript.Echo "Type : AAAA"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "IPv6 Address : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_CNAME
WScript.Echo "Type : CNAME"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Alias : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_MX
WScript.Echo "Type : MX"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Preference : " & objDnsRecord.Preference
WScript.Echo "Mail Exchange : " & objDnsRecord.MailExchange
Case objConstants.asDNS_TYPE_NS
WScript.Echo "Type : NS"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Name Server : " & objDnsRecord.NameServer
Case objConstants.asDNS_TYPE_PTR
WScript.Echo "Type : PTR"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Host : " & objDnsRecord.Address
Case objConstants.asDNS_TYPE_SOA
WScript.Echo "Type : SOA"
WScript.Echo "Name : " & objDnsRecord.Name
WScript.Echo "Name Server : " & objDnsRecord.NameServer
WScript.Echo "MailBox : " & objDnsRecord.MailBox
WScript.Echo "Serial : " & objDnsRecord.SerialNumber
WScript.Echo "Refresh : " & objDnsRecord.RefreshInterval
WScript.Echo "Retry Interval : " & objDnsRecord.RetryInterval
WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
WScript.Echo "Minimum TTL : " & objDnsRecord.MinimumTTL
End Select
WScript.Echo "TTL : " & objDnsRecord.TTL
WScript.Echo
Set objDnsRecord = objDnsServer.GetNextRecord
Wend
There are many working samples included with the product.
You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.
The ActiveSocket tool is a Network Communications ActiveX software component (SDK).
This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform,
including Visual Basic .NET, Visual CSharp .NET,
ASP .NET (VB,CS),
ASP,
Visual Basic,
Visual Studio/Visual C++,
Delphi,
PHP,
ColdFusion,
HTML,
VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.
|