VBS check for the output of netstat
I created this check:
' Check if windows or mac
if not objFSO.FolderExists("\\Client\C$\.") then
Wscript.Quit
end if
That check is to just see if its a Windows system or not. If it is a Windows machine then run the script if not I just want it to exit. I need to do another check to make sure both conditions are true that I am not sure how. There is an output using the netstat command. Under local address There is an address that has the port 1494 with the machine name of cag.domain.com. How can I include a check for that so that both parts must be true to run the script if not the script just closes. So that if \Client\C$. = True and local address :1494 and f开发者_如何转开发oreign address = cag.domain.com = false the script will not run.
I'm not currently at a windows machine so I can't give you the right parameters for netstat nor the correct regex pattern but to check the output of netstat
I'd do something along the lines of:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = ":1497[ ]cag[.]domain[.]com"
Set oExec = WshShell.Exec("netstat -a")
'wait for the end of process (busy wait, yuck!)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
'scan the command output flow
Dim oMatchColl, gotNetstat
gotMatch = false
Do While oExec.StdOut.AtEndOfStream <> True
oMatchColl = myRegExp.Execute(oExec.StdOut.ReadLine)
If oMatchColl.Count > 0 Then
gotNetstat = true
Exit Do
End If
Loop
Read more:
- Regular expressions for VBScript
- Netstat documentation
- WScript.Shell documentation
- RegExp object documentation
精彩评论