Re: How to parse output from a command

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




This works for me on WinXp/Win2K. Keep in mind, the .Exec method
requires WSH version 5.6. I used the nslookup option only to simplify
locating the IP address of the host and not the NameServer.


Function getHostIP(strHostName)
__________________________________________________________________________
Dim result
Dim strTmp
Dim objSH
Dim strCmdToExec
Dim strMsg
Dim ss
'_______________________________________________________________________________

strCmdToExec = "nslookup -querytype=ANY " & strHostName

Set objSH = WScript.CreateObject("WScript.Shell")
Set result = objSH.Exec("%comspec% /c " & strCmdToExec & " 2>&1")

Do While Not result.StdOut.AtEndOfStream
strMsg = result.StdOut.Readline & vbCrLf
If InStr(1, LCase(strMsg), "internet address", 1) Then
ss = Split(Trim(strMsg), "=", -1, 1)
strTmp = Replace(Trim(ss(1)), vbCrLf, "")
Exit Do
End If
Loop

If strTmp <> "" Then
getHostIP = strTmp
Else
getHostIP = False
End If

End Function



TDM


<snip>


.



Relevant Pages

  • Re: How to parse output from a command
    ... > These jobs will only be running on eight 2003 Servers, ... >> Dim result ... >> Dim strTmp ... >> getHostIP = False ...
    (microsoft.public.scripting.vbscript)
  • Re: How to parse output from a command
    ... These jobs will only be running on eight 2003 Servers, ... > Dim result ... > Dim strTmp ... > getHostIP = False ...
    (microsoft.public.scripting.vbscript)
  • Re: How to parse output from a command
    ... These jobs will be running on 2003 Servers, ... > Dim result ... > Dim strTmp ... > getHostIP = False ...
    (microsoft.public.scripting.vbscript)
  • Re: ping anomally
    ... ' strHostName String containing the hostname ... Dim result ... Dim objSH ... getHostIP = False ...
    (microsoft.public.scripting.wsh)