Re: Parsing NSLOOKUP for Error
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Feb 2008 09:46:07 -0600
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
--
.
- Follow-Ups:
- Re: Parsing NSLOOKUP for Error
- From: Tom Lavedas
- Re: Parsing NSLOOKUP for Error
- References:
- Parsing NSLOOKUP for Error
- From: Bryan
- Parsing NSLOOKUP for Error
- Prev by Date: Re: Cacls help
- Next by Date: Re: Script to get users of a group
- Previous by thread: Parsing NSLOOKUP for Error
- Next by thread: Re: Parsing NSLOOKUP for Error
- Index(es):
Relevant Pages
|