DnsServer ActiveX Control
Use the DnsServer control to build a DNS server application which responds to DNS queries. Features include:
- When a request is received, a corresponding event is raised. Write your own custom handling code in the event handler.
- The GetAddress event is raised when a client requests a domian name be resolved to a dot address (forward lookup).
- The GetName event is raised when a client requests a dot address be resolved to a domain name (reverse lookup).
- The GetMailServer event is raised when a client requests an email address be resolved to the mail server responsible for that email address (mx lookup).
- Use with the Dns control to build a "proxy" DNS server (passing on requests to another DNS server), or resolve names using a local datasource.
- Visual Studio .NET (.NET Framework)
- Visual Basic (VB)
- Visual C++ (VC++)
- Office 97/2000
|ClientException||ClientException is used only in the GetAddress, GetName, and GetMailServer events. After the event is fired, the DnsServer Control will expect this property to be set if you wish to return an error condition to the client. The default value is dnsOk.|
|LocalAddress||Returns the address in use while the socket is active and an empty string when the UDP socket is closed.|
|LocalPort||Returns the port number in use while the socket is active and 0 when the socket is closed. When the Protocol property of the UDP Control is not ptUdp, LocalPort returns 0.|
|Timeout||Controls the blocking behavior of methods that can be used in blocking and non-blocking ways.|
|Abort||Abort any blocking method and release all system resources.|
|About||Show the About Box.|
|Close||Release system resources.|
|Open||Allocate a socket for sending and receiving datagrams.|
|Trace||Start or stop the accumulation of trace or debug data. Once started, this method accumulates data until it is turned off.|
|Error||Fires when an error condition occurs.|
|GetAddress||Fires when a DNS type A request has been received.|
|GetMailServer||Fires when a DNS type MX request has been received.|
|GetName||Fires when a DNS type PTR request has been received.|
How easy is the DnsServer control to use? Check out the VB examples below, which demonstrates responding to a request to resolve an address.
' Don't forget to add a reference to Microsoft Scripting Runtime.
Dim LookupTable As New Dictionary
Private Sub StartServer()
' Start the server
' Initialize the "phony" lookup table (replace this with a real data source)
LookupTable.Add "127.0.0.1", "localhost"
LookupTable.Add "18.104.22.168", "myserver.com"
LookupTable.Add "22.214.171.124", "dart.com"
Private Sub DnsServer1_GetName(ByVal Address As String, ByVal Names As
DartDnsServerCtl.IDartStrings, OwnerName As String, ByVal Request As
' Check if they are requesting a recursive search or a local search. This example
only handles local
' searches, so send an exception if it is recursive.
If Not Cbool(Request.RecursiveFlag) Then
' Look up the name
Dim Name As String
Name = MyGetHostName(Address)
' See if a valid name was found.
If Name <> "" Then
' Add the name to the response
' The owner is the local server.
OwnerName = DnsServer1.LocalAddress
' Name not found. Return a not found exception.
DnsServer1.ClientException = dnsNameError
' Uh oh, this server does local lookups only
DnsServer1.ClientException = dnsNotImplemented
Private Function MyGetHostName(ByVal Name As String)
' Use the LookupTable to get the name from the IP.
If LookupTable.Exists(Address) Then
MyGetHostName = LookupTable.Item(Address)
MyGetHostName = ""