WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

NSLookup

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

DNS Lookup Return Multiple Host

 Keywords: DNS Lookup Return Multiple Host IP ADDRESS  

Question:

In our DNS setup, we have some host with multiple IPs (round robin DNS in some cases, multiple NICs in other cases). As a result, the machine "TestMachine123" may have DNS records for IP 1.1.1.1, 1.1.1.2, and 1.1.1.3.

Is it possible to query AD/DNS/etc to return back a list of ALL IPs associated with a given host? ipHost2Addr only returns one.

We are running a Win2003 environment and all DNS queries are handled internally on our Win2003 servers.

Answer:

NSlookup should accomplish what you need. Nslookup.exe is a command-line administrative tool for testing and troubleshooting DNS servers. http://support.microsoft.com/kb/200525

something like:

nslookup -"set q=all" TestMachine.Mydomain.com
should return the info you need.

#DefineFunction CaptureDosOutput(DosCommand)

   DataArray=ArrDimension(3)               ;Allocate return array
   ArrInitialize(DataArray,"")             ;initialize to all null strings
   oShell = ObjectOpen("WScript.Shell")    ;open shell object
   oScriptExec = oShell.Exec(DosCommand)   ;run the command

   ;Open output objects
   oStdOut = oScriptExec.StdOut
   oStdErr = oScriptExec.StdErr

   While (oScriptExec.Status==0)           ;wait for completion

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF)
      EndWhile

      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF)
      EndWhile

      TimeDelay(0.1)
   EndWhile

   ;Get remainder of data, if any

      ;Caputure StdOut data
      oStdOut = oScriptExec.StdOut
      While ! oStdOut.AtEndOfStream
         strLine = oStdOut.ReadLine
         DataArray[1] = StrCat(DataArray[1],strLine,@CRLF)
      EndWhile

      ;Capture StdErr data
      oStdErr = oScriptExec.StdErr
      While ! oStdErr.AtEndOfStream
         strLine = oStdErr.ReadLine
         DataArray[2] = StrCat(DataArray[2],strLine,@CRLF)
      EndWhile


   DataArray[0]=oScriptExec.ExitCode         ;save errorlevel/exit code

   ;Close handles that were opened
   ObjectClose(oStdOut)
   ObjectClose(oStdErr)
   ObjectClose(oScriptExec)
   ObjectClose(oShell)

   ;Return the array
   Return(DataArray)

#EndFunction

IPList = ""
QueriedServer = "testMachine.mydomain.com"
DosCommand = StrCat('nslookup -"set q=all" ', QueriedServer)
DOSResults = CaptureDosOutput(DosCommand)
DOSResults = DOSResults[1]
DOSResults = StrReplace(DOSResults, @CRLF, @CR)
Numlines = ItemCount(DOSResults, @CR)
For i = Numlines To 1 By -1
   CurrentLine = ItemExtract(i, DOSResults, @CR)
   If ItemLocate(StrLower(QueriedServer), StrLower(CurrentLine), @TAB)
      CurrentIP = ItemExtract(-1, CurrentLine, " ")
      IPList = ItemInsert(CurrentIP, -1, IPList, @TAB)
   EndIf
Next
Message ("The list of IP for that given host", IPList)
Exit

Article ID:   W18263
Filename:   DNS Lookup Return Multiple Host.txt
File Created: 2009:08:27:09:49:32
Last Updated: 2009:08:27:09:49:32