Re: Parsing NSLOOKUP for Error

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Bryan wrote:

I'm writing a script to do a nslookup and return whether the lookup was
successful but one things I've noticed is that if I provide an invalid
name
server to do the lookup, the script still executes no problem because it
defaults to the name server configured on the server or workstation. How
can
I get around this?

Basically, I want to capture the following output after the script runs
the
the following:
nslookup <hostname> <bogusnameservername>

The output I get is:
*** Can't find server address for 'bogusnameservername':
Server: <valid nameserverFQDN>
Address: 192.168.10.27


I'm reusing some the following code in my script:
Function DNSlookup(strHost, strNameServer)
sCommand = "%ComSpec% /c nslookup " & strHost & " " & strNameServer
'WScript.Echo sCommand
Set objShellRun = objShell.Exec(sCommand)
Proceed = 0
Do Until objShellRun.StdOut.AtEndOfStream
sLine = Trim(objShellRun.StdOut.ReadLine)
NameTag = LCase(Left(sLine,5))
Select Case NameTag
Case "name:"
Proceed = 1
End Select
If Proceed = 1 Then
sData = Trim(Mid(sLine,6))
aLine = Split(sLine, ":")
sData = Trim(aLine(1))
Exit Do
End If
Loop

How can I parse for:
*** Can't find server address for 'bogusnameservername':

Perhaps use the StdOut.ReadAll method, so you have the entire output in one
variable and don't need to loop through each line. You can use the InStr
function to look for the string "Can't find server address". The function
returns 0 if the string is not found, a positive integer otherwise.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script ... # have to place corresponding `LoadModule' lines at this location so the ...
    (perl.beginners)
  • Re: Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script Runs perfectly fine from the command prompt. ... # This is the main Apache HTTP server configuration file. ... LoadModule actions_module modules/mod_actions.so ...
    (perl.beginners)
  • Same Internal Server Error from last two days
    ... I am trying to run a Hello World Perl Script in Apache 2.2. ... But its constantly giving me Internal Server Error.The script ... # have to place corresponding `LoadModule' lines at this location so the ...
    (perl.beginners)
  • Re: Regarding a selection for mobile code/scripting language
    ... Client Side scripting, so the server can send script commands to the client. ... I decided they should be scripted and mobile code. ...
    (Vuln-Dev)
  • Re: Javascript code
    ... On serverside you cannot debug clientside script. ... This string on server can be changed dinamically for accept ... RegisterClientScriptBlock MSDN remark: ...
    (microsoft.public.dotnet.framework.aspnet)