Recipe13.12.Querying Resource Records


Recipe 13.12. Querying Resource Records

Problem

You want to query resource records. You might want to do this if you need to find the IP address that is mapped to a particular host name or vice versa.

Solution

Using a graphical user interface

The DNS snap-in does not provide an interface for searching resource records.

Using a command-line interface

In the following command, replace <RecordType> with the type of resource record you want to find (e.g., A, CNAME, SRV) and <RecordName> with the name or IP address of the record to match.

> nslookup -type=<RecordType> <RecordName>

Using VBScript
' This code prints the resource records that match ' the specified name ' ------ SCRIPT CONFIGURATION ------ strQuery = "<RecordName>" ' ------ END CONFIGURATION ---------     set objDNS = GetObject("winMgmts:root\MicrosoftDNS") set objDNSServer = objDNS.Get("MicrosoftDNS_Server.Name="".""") set objRRs = objDNS.ExecQuery(" select * " & _                           " from MicrosoftDNS_ResourceRecord" & _                           " where  OwnerName = """ & strQuery & """" & _                           " Or  DomainName = """ & strQuery & """" & _                           " Or RecordData = """ & strQuery & """") if objRRs.Count < 1 then    WScript.Echo "No matches found for " & strHostName & " of " _                  & strRecordType & " type" else    for each objRR in objRRs       WScript.Echo objRR.TextRepresentation    next end if

Discussion

Using a command-line interface

You can leave off the -type switch and the command will find any A, PTR, and CNAME records that match <RecordName>. You can also run nslookup from interactive mode, which you can enter by typing nslookup at a command prompt with no additional parameters.

Using VBScript

In the VBScript code, I used a WQL query to find all matching resource records. This is a good example of how powerful the DNS WMI Provider can be. The query finds any object of the MicrosoftDNS_ResourceRecord class that has an OwnerName, DomainName, or RecordData field equal to the <RecordName>. This is not the most efficient query if the server supports multiple large zones, so you may want restrict it to search for specific types of records by adding criteria to match RecordType = <Type>.

See Also

MSDN: MicrosoftDNS_ResourceRecord



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net