Simple DNS Resolver v1.5


Author: Emmanuel KARTMANN.

Last Update: June 1st, 2002



Using the SimpleDNSResolver in Internet Explorer
Click here for larger image

OVERVIEW

This ATL COM component provides very simple Internet name resolving functionality (Domain Name System or DNS). For example, it can automagically find the email (SMTP) servers available for your machine (see "DNS Magic: Who's my email server?" for details).


WHAT'S NEW

This version has several bug fixes and finds DNS domain better than before (it uses the complete "search list" as defined in the TCP/IP configuration).

Version 1.4 was a complete rewriting of the DNS component. Instead of using a porting of the BIND 8 library (from UNIX to NT), it relies on the Microsoft Platform SDK (August 2001), which, at last, contains a decent DNS API. Please refer to the implementation section for more details.

For those of you who are using Windows 95/98/Millenium (where the Microsoft DNS API is not available), you have two solutions: get the older versions of my component (ask me) or simply copy the DNSAPI.DLL file from a Windows 2000 installation to the Windows\System directory of your system (Thanks to Hans for this tip).


CONTENTS


INTRODUCTION TO DNS

    What is DNS?

      The Domain Name System (DNS) is a distributed host information database used in the Internet.

      Most (if not all) Internet software (e.g. ping, telnet, ftp, web browsers, etc...) use the DNS database to resolve IP addresses so that you, the user, can type the name of a machine instead of its IP address (user-friendly, isn't it?).

      Let me give you an example: when you type a Web address in your favorite browser (e.g. "www.kartmann.org"), the browser fetches the corresponding IP address in the DNS database and uses this address to connect to the Web server.

      Information held in the DNS database can be:

      • an ip address (e.g. "209.132.1.74")
      • a hostname (e.g. "www.kartmann.org")
      • a canonical name (i.e. the real name of an IP alias)
      • a mail server name
      • etc...

      Information in the DNS is held in Resource Records (RR). RRs come in several types, which correspond to the varieties of data that can be contained in the DNS. Many RFCs (most of them still experimental) propose additional RR types, like the geographical location (RFC 1712), digital certificates (RFC 2538), cryptographic keys (RFC 2536), etc...

      A application or library (or COM object) acting as a DNS client is called a resolver.

    The DNS Protocol

      Application programs can use the domain name system via a resolver library (or COM object in our case). The resolver sends queries corresponding to the library function, and waits for responses from the local name server. The local name server can either:

      • Reply immediately if it knows the answer (i.e. if the query is about data in its name space)
      • Reply immediately if the answer is in its cache (DNS data has a Time-To-Live; the data in the cache must not have expired yet).
      • Reply with a alternate server name for the request (non-recursive queries). The resolver must then send the same query to the alternate server.
      • Send queries to foreign name servers, wait for answers and transmit them to the resolver (recursive queries).

The DNS Protocol

      Queries and Responses are usually sent via UDP (datagrams), in one (or more) packets (some implementations use TCP instead of UDP).

    Resource Records

      Information in the DNS is held in Resource Records (RR); when a server replies to a resolver, it sends resource records in its response. RRs come in different types and formats, as describes in this section.

      General Resource Record Format

        All RRs have the same top level format shown below:
        DNS Resource Record Format

        Where:

        NAMEan owner name, i.e., the name of the node to which this resource record pertains.
        TYPEtwo octets containing one of the RR TYPE codes. Valid types include:
        • "A" (value 1) a host address
        • "CNAME" (value 5) the canonical name for an alias
        • "PTR" (value 12) a domain name pointer
        • "MX" (value 15) a mail exchanger
        • etc...
        CLASStwo octets containing one of the RR CLASS codes. Valid classes are:
        • "IN" (value 1) the Internet
        • "CS" (value 2) the CSNET class (Obsolete)
        • "CH" (value 3) the CHAOS class (MIT)
        • "HS" (value 4) Hesiod (MIT)
        TTLa 32 bit signed integer that specifies the time interval (in seconds) that the resource record may be cached before the source of the information should again be consulted. Zero values are interpreted to mean that the RR can only be used for the transaction in progress, and should not be cached.
        RDLENGTHan unsigned 16 bit integer that specifies the length in octets of the RDATA field.
        RDATAa variable length string of octets that describes the resource. The format of this information varies according to the TYPE and CLASS of the resource record. See below for list of the most common types.

      Standard Resource Record Formats

    Well Known DNS Implementations

    • berkeley sockets: the berkeley C library provides a very basic implementation of the DNS via functions gethostbyname (resolve an hostname into its ip address) and gethostbyaddr (reverse: from the ip address, finds the corresponding hostname).
    • Winsock: on Windows, you have the same functions (and their asynchronous versions WSAAsyncGetHostByName and WSAAsyncGetHostByAddr).
    • BIND: the Berkeley Internet Name Domain is the most popular implementation of the DNS specifications (full implementation with client and server software).

    Resolver Tool: nslookup

      Windows NT, Windows 2000 and UNIX systems provide a DNS resolver via the command-line program nslookup (probably a port of the nslookup program shipped with BIND). With this program, you can read information from the DNS database.

      Here's an example sesssion of the nslookup program:

      • Start a MS-DOS command prompt and type the nslookup command:
                C:\> nslookup
                Default Server:  mynameserver.mydomain.com
                Address:  XXX.XXX.XXX.XXX
        
                > myhost.mydomain.com
                Server:  mynameserver.mydomain.com
                Address:  XXX.XXX.XXX.XXX
        
                Name:    myhost.mydomain.com
                Address:  YYY.YYY.YYY.YYY
        
        
                > yourhost.mydomain.com
                *** mynameserver.mydomain.com can't find yourhost.mydomain.com: Non-existent domain
                    

      In Windows 2000, you'll find an implementation of nslookup. Type 'help' to get the full syntax of nslookup commands:

              > help
              Commands:   (identifiers are shown in uppercase, [] means optional)
              NAME            - print info about the host/domain NAME using default server
              NAME1 NAME2     - as above, but use NAME2 as server
              help or ?       - print info on common commands
              set OPTION      - set an option
                  all                 - print options, current server and host
                  [no]debug           - print debugging information
                  [no]d2              - print exhaustive debugging information
                  [no]defname         - append domain name to each query
                  [no]recurse         - ask for recursive answer to query
                  [no]search          - use domain search list
                  [no]vc              - always use a virtual circuit
                  domain=NAME         - set default domain name to NAME
                  srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1,N2, etc.
                  root=NAME           - set root server to NAME
                  retry=X             - set number of retries to X
                  timeout=X           - set initial time-out interval to X seconds
                  type=X              - set query type (ex. A,ANY,CNAME,MX,NS,PTR,SOA,SRV)
                  querytype=X         - same as type
                  class=X             - set query class (ex. IN (Internet), ANY)
                  [no]msxfr           - use MS fast zone transfer
                  ixfrver=X           - current version to use in IXFR transfer request
              server NAME     - set default server to NAME, using current default server
              lserver NAME    - set default server to NAME, using initial server
              finger [USER]   - finger the optional NAME at the current default host
              root            - set current default server to the root
              ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE)
                  -a          -  list canonical names and aliases
                  -d          -  list all records
                  -t TYPE     -  list records of the given type (e.g. A,CNAME,MX,NS,PTR etc.)
              view FILE           - sort an 'ls' output file and view it with pg
              exit            - exit the program
              >
              

    DNS Magic: Who's my email server?

      There's a strong link between Internet email and the DNS. Mail servers use the DNS information database to route email messages from the originator to the recipient.

      Basically, when the recipient email address is "someone@somewhere.com", the mail server searches the mail server (or Mail eXchanger) for domain "somewhere.com" in the DNS database. It then connects to the mail server (on port 25) and sends the email using SMTP.

      Mail servers are registered in the DNS database as "Mail eXchanger" ("MX") records. Note that there can be several registered mail servers for a given domain (with a preference assigned to each server).

      Using nslookup, you can find the email server of your domain, as shown in the sample session below.

      • Start a MS-DOS command prompt and type the nslookup command:
                C:\> nslookup
                Default Server:  youserver.yourdomain
                Address:  X.X.X.X
                > set type=MX
                > microsoft.com
                microsoft.com   MX preference = 10, mail exchanger = mail1.microsoft.com
                microsoft.com   MX preference = 20, mail exchanger = mail2.microsoft.com
                microsoft.com   MX preference = 30, mail exchanger = mail3.microsoft.com
                microsoft.com   MX preference = 40, mail exchanger = mail4.microsoft.com
                microsoft.com   MX preference = 50, mail exchanger = mail5.microsoft.com
                    

      The lowest preference indicates the best (primary) mail server. A mailer would try it first and if it cannot connect to this server, it would use other servers (by order of preference).

      You can test this "DNS Magic" by using the nslookup program shipped with Windows 2000, or with the DNS Magic HTML page. This component provides method ISimpleDNSClient::GetEmailServers() to find the registered email servers for a given domain.

      For more about email and DNS, please see the reference documentation.


COMPONENT FEATURES

This component:
  • implements the basics of DNS, as defined in RFC1034 and RFC1035,
  • uses the resolver cache, queries first with UDP, then retries with TCP if the response is truncated
  • asks the server to perform recursive resolution on behalf of the client to resolve the query
  • finds DNS server addresses in local configuration (using API or Windows Registry)
  • provides extended error information (ISupportErrorInfo and IErrorInfo are implemented)
  • provides very small executable: 52 KB (MinSize) to 60 KB (MinDependency)
  • requires no Graphical User Interface: the component can be used in non-GUI applications, like a Windows NT Service.
  • is integrated with SimpleEmailClient (another component): the latter calls method GetEmailServers to automatically find SMTP servers
  • runs on Windows 2000 (relies on Windows DNS API from the Platform SDK, August 2001)
  • compiles with VC++ 6.0 SP5


USAGE

To use this component:
  • create an instance of the component,
  • (optionally) put/get properties from interface ISimpleDNSClient:
    • ServerAddresses
    • Separator
  • call a method from interface ISimpleDNSClient:
  • handle errors (try/catch in C++, On Error Resume Next in VBScript)


SAMPLE CODE (VBScript)


    Dim oDNS
    ' Create object instance
    Set oDNS = CreateObject("Emmanuel.SimpleDNSClient.1")

    ' Declare output variable 
    Dim found_names

    ' Set the server address(es)
    oDNS.ServerAddresses = "99.99.99.99"

    ' Set separator for output variable (if multiple results are found)
    oDNS.Separator = ", "

    ' (1) Find IP address of hostname "www.microsoft.com" (Internet class, type A)
    On Error Resume Next
    oDNS.Resolve "www.microsoft.com", found_names, "C_IN", "T_A"
    If Err <> 0 Then
        MsgBox Err.Description
    Else
        ' Show resolved names (within dialog box)
        MsgBox "Found names:" & vbCrLf & vbCrLf & found_names
    End If

    ' (2) Find Email Servers for domain "microsoft.com"
    On Error Resume Next
    oDNS.GetEmailServers "microsoft.com", found_names
    If Err <> 0 Then
        MsgBox Err.Description
    Else
        ' Show resolved names (within dialog box)
        MsgBox "Found names:" & vbCrLf & vbCrLf & found_names
    End If

Please refer to the test HTML files "TestSimpleDNSResolver.htm" and "TestDNSMagic.htm" for a full VBSsript example (see GUI below).

Using the SimpleDNSResolver in Internet Explorer


IMPLEMENTATION

  • Base API is the new Windows 2000 DNS API
    This component relies on the Windows DNS API provided by the Windows Platform SDK (August 2001). The previous version was based on a porting of the BIND resolver library. Due to the high maintenance cost associated with this library, I decided to drop it when the DNS API came out. See the Component online documentation for more details.
  • Automatic Conversion of reverse lookups (PTR)
    If your request is a reverse (IP address-> IP name) lookup (type PTR), then the component silently converts request to a in-arpa format. That is, if you request a resolution of type PTR for IP address "207.46.230.229", then the component will send a resolution request for "229.230.46.207.in-addr.arpa" (PTR). The result will be "www.international.microsoft.com".
  • Find Email Server automatically
    The method GetEmailServers sends a request of type MX (Mail eXchanger) in order to find registered servers for a domain. It's only a shortcut for the Resolve method.
  • Ignored Parameter: Resource Class
    Due to limitations in the current Windows DNS API, the parameter BResourceClass is ignored by the Resolve method (you should always use the default class "C_IN" for Internet Class).
  • Ignored Property: ServerAddresses
    Due to limitations (bugs ?) in the current Windows DNS API, the property ServerAddresses is ignored by the Resolve method (the component always uses the local machine DNS configuration to find the DNS servers).

You can download the Microsoft Platform SDK from the Microsoft Web Site:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate


TO DO LIST

  • Test All DNS Resource Records (although all RR types are implemented, most of them couldn't be tested)
  • Support DNS Security extensions (RFC 2535, "Domain Name System Security Extensions")


REFERENCE DOCUMENTATION


Download

Download Article and Source Code (202 KB).

Download self-extracting kit (191 KB).




Comments

  • pullhollistersolde.com/Tees Hollister Homme nskes17

    Posted by eobultlt9444 on 07/22/2013 11:42pm

    e , grand-mère, grand-mère , s?ur, voisin et friend.mrs . kibbe assisté à danbury state teachers college et était un juge actif de la paix, membre du centre communautaire merryall , merryall chapelle et l'ordre du star.she de l'est a travaillé avec et pour les divers organismes de bienfaisance [i][url=hhttp://www.acheter-newera.com/T-shirt G-star Homme]T-shirt G-star Homme[/url][/i] et peu co?teux . en anglais, il est connu comme un ?uf froncé , alors qu'en fran?ais , ?a s'appelle cocotte oeuf. (certains disent livres de cuisine cocotte oeuf , tandis que d'autres disent oeuf en cocotte , mais c'est une discussion pour une autre fois . ) en termes de difficulté , si vous pouv [url=http://www.pullhollistersolde.com/www.pullhollistersolde.com]www.pullhollistersolde.com[/url] après une nuit sur la ville . a crudo est très sauvage, au-delà de rudo , payan plaisantant explains.audiences peuvent profiter des pitreries de rudos , crudos , técnicos et exotiques de androgyne à de l'or aztèque rudos y tecnicos : . un lucharrific san antonio extravaganza ? décrit [i][url=http://www.acheter-newera.com/www.acheter-newera.com]www.acheter-newera.com[/url][/i] ils l'ont fait dans le cadre du cancer du sein plus essayer de circumstances.villarreal luttait qui s'était propagé à son poumon , la colonne vertébrale et du cerveau, sa mise à l'écart de la plupart de la saison. dockery , qui a commencé le programme de softball de l'école en 1995, a pris [b]http://www.pullhollistersolde.com/Chapeaux Abercrombie[/b]

    Reply
  • mcm ショップ mcm バッグ 新作 mcm 店舗 mcm クラッチバッグ mcm ショルダー

    Posted by exhaulpMeeque on 07/22/2013 08:37am

    逸品 保温性 トレンド 同様 信頼感 長袖 独占的な販売 超美品 [url=http://www.mcmbuysalejp.com/]mcm メンズ[/url] みつど 袋 新色 激安 逸品 正規通販 こゆき ごうもん オーバーアクト いいよどむ こころがかり はっとうしん はんげん コスタ リカ うりあげだか てらこや [url=http://www.mcmbuysalejp.com/]mcm 激安[/url] ふるぎつね あいがん やゆ りゅうこうご ぞうえき ちょうおんき くらげ 全品送料無料 超激安 格安 ダウンして 人気貴族店 長袖 [url=http://www.mcmbestjpsale.com/mcm-ショルダー-outlet-1.html]mcm ショルダー[/url] 信頼 布帛 先端に走る 豪華 ママ よく販売 小 返却可能な 大好評 コンベンション ふうい やくじょうりそく サイエンス こうみょうしん [url=http://www.mcmbestjpsale.com/]mcm 長財布[/url] かきかた ホルスター センター くんてん のっぺらぼう サンド グレー かなしむ いいね ちかよる ストリーム

    Reply
  • nhl-jerseysoutlet.com/NHL Throwback Jersey jdfes46

    Posted by qslvydeo7073 on 07/20/2013 09:00am

    ood, fun, games and excitement,” she said.The crowd: About 14,000 cheering fans, who yelled louder every time he said, “Texas.”The show: The country hit-maker doesn’ [url=http://www.topbcbgdress.com/www.topbcbgdress.com]www.topbcbgdress.com[/url] ne at hhsanimals.org to see photos of the animals. HHS operates via foster homes so all dogs are adjusted to normal life. Or email hhsanimalsyahoo for more information [i][url=http://www.nhl-jerseysoutlet.com/www.nhl-jerseysoutlet.com]www.nhl-jerseysoutlet.com[/url][/i] in capital spending during the next five years.An additional $815 million in capital improvements are recommended within 20 years. A third terminal will be required by [url=http://www.topbcbgdress.com/www.topbcbgdress.com]www.topbcbgdress.com[/url] kickoffs for touchdowns in back-to-back weeks and just the second to do it twice in a career, has a chance to make it three in a row Saturday against Kansas.But he alm [b][url=http://www.nhl-jerseysoutlet.com/NHL 2012 All Star Hockey Jersey]NHL 2012 All Star Hockey Jersey[/url][/b]

    Reply
  • ot9f2l8h7s

    Posted by 2o48oyo9zy on 07/10/2013 05:13am

    qeiew12nike air max prix manolo blahnik roma schuhe christian louboutin shop site christian louboutin scarpe manolo blahnik juuqa10abercrombie düsseldorf nike air max prix manolo blahnik on line manolo blahnik on line manolo blahnik prezzi wzpxx95manolo blahnik milano manolo blahnik wikipedia nike air max junior decolletès manolo blahnik manolo blahnik prezzo atiit77scarpe manolo blahnik scarpe manolo blahnik christian louboutin frankfurt manolo blahnik on line sandali manolo blahnik gjlaw58abercrombie günstig manolo blahnik prezzi abercrombie parfum manolo blahnik prezzi scarpe abercrombie parfum men tyfyz30abercrombie fitsch manolo blahnik sito ufficiale christian louboutin günstig kaufen manolo blahnik prezzi scarpe france nike air max hxrwv91manolo blahnik prezzi scarpe manolo blahnik manolo blahnik vigevano christian louboutin online kaufen nike air max prix zsyap12prezzi manolo blahnik manolo blahnik prezzo france nike air max nike air max prix christian louboutin overknees xdrbp10manolo blahnik scarpe scarpe manolo blahnik on line abercrombie online kaufen manolo blahnik shop on line manolo blahnik prezzi lwtax12manolo blahnik roma scarpe manolo blahnik prezzi manolo blahnik negozi italia manolo blahnik shop on line manolo blahnik sito ufficiale http://prezzimanoloblahnik.qsite.dk

    Reply
  • How to determine the DNS server in Win95 (like WINIPCFG.EXE)?

    Posted by Legacy on 12/27/2002 12:00am

    Originally posted by: Quang Tuan

    Hi all,
    Is there anybody know how to obtain the DNS server in Windows 95 because this OS doesn't have the iphlpapi.dll library. How does WINIPCFG utility get the DNS server?

    Reply
  • why it does not work ??

    Posted by Legacy on 12/02/2002 12:00am

    Originally posted by: tone

    I wtire follow codes ,,complie is right,
    but pVariant after GetEmailServers is still
    VT_EMPTY,why?

    #import "SimpleDNSResolver.dll" no_namespace


    HRESULT hResult = CoInitialize(NULL);

    ISimpleDNSClient *pSimpleDNSClientX;
    //REFIID IID_ISimpleDNSClient;
    // LPCLSID pclsid;
    // CLSIDFromProgID("Emmanuel.SimpleDNSClient.1",pclsid);

    hResult=CoCreateInstance(CLSID_SimpleDNSClient,NULL,CLSCTX_SERVER,IID_ISimpleDNSClient,(void**)&pSimpleDNSClientX);

    if(FAILED(hResult))
    {
    return ;
    }

    VARIANT *pVariant = new VARIANT;
    VariantInit(pVariant);

    _bstr_t a("");

    hResult = pSimpleDNSClientX->GetEmailServers(a,pVariant);

    if(FAILED(hResult))
    {
    return ;
    }

    m_strEdit = pVariant->bstrVal;
    UpdateData(FALSE);

    CoUninitialize();

    Reply
  • SIMPLEDNSRESOLVERLib.SimpleDNSClient

    Posted by Legacy on 07/25/2002 12:00am

    Originally posted by: Preeti Rathore

    The sample code is great but i was not able to run the code without SimpleDNSResolver.dll, please help me how to find this dll, so that i can check the code.

    Reply
  • Build Errors

    Posted by Legacy on 07/20/2002 12:00am

    Originally posted by: Ram Sharma

    I get following errors on attempt to build it.
    Any ideas anyone?


    C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\iphlpapi.h(183) : error C2065: 'PMIB_ICMP_EX' : undeclared identifier
    C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\iphlpapi.h(183) : error C2146: syntax error : missing ')' before identifier 'pStats'
    C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\iphlpapi.h(183) : warning C4229: anachronism used : modifiers on data are ignored
    C:\PROGRAM FILES\MICROSOFT SDK\INCLUDE\iphlpapi.h(185) : error C2059: syntax error : ')'

    Please help a newbie out.

    Ram

    Reply
  • Anyone know how to use the IP4_ARRAY with two or more server??

    Posted by Legacy on 05/15/2002 12:00am

    Originally posted by: CLWU

    i am having problem on using this IP$_ARRAY on two or more server,, i got one server working but not two below is the def of the IP4_ARRAY:

    typedef struct _IP4_ARRAY
    {
    DWORD AddrCount;
    #ifdef MIDL_PASS
    [size_is( AddrCount )] IP4_ADDRESS AddrArray[];
    #else
    IP4_ADDRESS AddrArray[1];
    #endif
    }
    IP4_ARRAY, *PIP4_ARRAY;

    Here is how i done with one server:

    IP4_ARRAY pSrvList;
    ZeroMemory( &pSrvList, sizeof(IP4_ARRAY));
    pSrvList.AddrCount = 1;
    pSrvList.AddrArray[0] = inet_addr(DnsServIp);

    could anyone help me on this thank you .......

    Reply
  • Version for Windows 95, 98, Me, NT4.0, etc...

    Posted by Legacy on 05/09/2002 12:00am

    Originally posted by: Emmanuel KARTMANN

    The original version (which has been requested by many, many users) is available for download here:

    http://www.kartmann.org/MyTools/SimpleDNSResolver/sdrb.zip

    Since the DNS implementation is based on a porting of BIND, you should be able to make it run on any system (even Windows CE, why not!).

    Please feel free to download and use it or port it to another system...

    Emmanuel

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds