Dim arrNAStrings(5)
REM French
arrNAStrings(0) = "Réponse ne faisant pas autorité :"
REM German
arrNAStrings(1) = "Nicht autorisierende Antwort:"
REM Spanish
arrNAStrings(2) = "Respuesta no autoritativa:"
REM Italian
arrNAStrings(3) = "Risposta da un server non autorevole:"
REM English
arrNAStrings(4) = "Non-authoritative answer:"
REM Portuguese
arrNAStrings(5) = "Nao é resposta de autorizaçao:"
Set objShell = CreateObject("WScript.Shell")
Set oArgs = WScript.Arguments
If (oArgs.Count <> 5) Then
ErrorMessage = "Expected 5 arguments. Received " & CStr(oArgs.Count)
ErrorNumber = 1
Call ReturnPropertyBag
End If
Select Case strQueryType
Case "A"
boolQTypeValid = True
Case "CNAME"
boolQTypeValid = True
Case "PTR"
boolQTypeValid = True
Case "NS"
boolQTypeValid = True
Case "SOA"
boolQTypeValid = True
Case Else
boolQTypeValid = False
End Select
If Not boolQTypeValid Then
ErrorMessage = "Query Type must be A, CNAME, NS, PTR, or SOA"
ErrorNumber = 2
Call ReturnPropertyBag
End If
Select Case strAcceptNonAuth
Case "TRUE"
boolIgnoreNAValid = True
Case "FALSE"
boolIgnoreNAValid = True
Case Else
boolIgnoreNAValid = False
End Select
If Not boolIgnoreNAValid Then
ErrorMessage = "AcceptNonAuthoritative must be TRUE or FALSE"
ErrorNumber = 3
Call ReturnPropertyBag
End If
boolAcceptNonAuth = CBool(strAcceptNonAuth)
If (strHostName = "") Or (strServerName = "") Then
ErrorMessage = "HostName and ServerName may not be blank"
ErrorNumber = 4
Call ReturnPropertyBag
End If
strCommand = "NSLookup.exe -timeout=" & CStr(intQueryTimeout) & " -querytype=" & strQueryType & " " & strHostName & " " & strServerName
ON ERROR RESUME NEXT
Set objWshScriptExec = objShell.Exec(strCommand)
If Err.Number <> 0 Then
ErrorNumber = Err.Number
ErrorMessage = Err.Description
Call ReturnPropertyBag
End If
ON ERROR GOTO 0
Set objStdOut = objWshScriptExec.StdOut
While Not objStdOut.AtEndOfStream
strTempLine = objStdOut.ReadLine
strTempLine = Replace(strTempLine, vbCr, "")
strTempLine = Replace(strTempLine, vbLf, "")
strStdOut = strStdOut & strTempLine
Wend
Set objStdErr = objWshScriptExec.StdErr
While Not objStdErr.AtEndOfStream
strTempLine = objStdErr.ReadLine
strTempLine = Replace(strTempLine, vbCr, "")
strTempLine = Replace(strTempLine, vbLf, "")
strTempLine = Replace(strTempLine, Chr(130), Chr(233))
strTempLine = Replace(strTempLine, Chr(135), Chr(231))
boolIsNonAuth = CBool("False")
For Each NAString In arrNAStrings
If strTempLine = NAString Then
boolIsNonAuth = CBool("True")
End If
Next
If boolAcceptNonAuth And boolIsNonAuth Then
strIgnoredErr = strIgnoredErr & strTempLine
ElseIf strTempLine = "*** Can't find server name for address " & strServerName & ": Non-existent domain" Then
strIgnoredErr = strIgnoredErr & strTempLine
Else
strStdErr = strStdErr & strTempLine
End If
Wend
If strStdErr = "" Then
strResult = "Success"
Else
strResult = "Query-Failure"
End If
If (strQueryType = "CNAME") And Not ( Instr(1, strStdOut, "canonical name =", 1) >= 1 ) Then
strResult = "Query-Failure"
End If
Call ReturnPropertyBag
Sub ReturnPropertyBag
Dim oAPI, oBag, HexErrorNumber
HexErrorNumber = "0x" & Hex(ErrorNumber)
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()