View Single Post
  #2 (permalink)  
Old February 16th, 2005, 12:40 PM
mmcdonal mmcdonal is offline
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What is the sequence of events here? What is displayed on the command screen? How is the text on the command screen put there?

Here is something you can use to pass a command to comspec (CMD in all versions of Windows) and retrieve text that is sent back from the app. In this case, Ping is called, and the script checks to see if there is a reply. This will work on a Private Class C using 192.168.0 as the subnet, and it will ping 10 addresses in this range. You can substitute a strAddress from your own subnet, and your own counter range.

'==========
Dim strAddress1
Dim strAddress
Dim i

i = 1

strAddress = "192.168.0."
strAddress1 = strAddress & i

Do Until i = 11
    Set objShell = CreateObject("WScript.Shell")
    Set objExecObject = objShell.Exec _
    ("%comspec% /c ping -n 3 -w 1000 " & strAddress1)
        Do While Not objExecObject.StdOut.AtEndOfStream
            strText = objExecObject.StdOut.ReadAll()
            If InStr(strText, "Reply") > 0 Then
            WScript.Echo strAddress1 & " - Reply received."
            Else
            WScript.Echo strAddress1 & " - No reply received."
            End If
        Loop
    i = i + 1
    strAddress1 = strAddress & i
Loop
'==========

This script returns this information on my network (of course I changed the real subnet):

'==========
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

192.168.0.1 - Reply received.
192.168.0.2 - Reply received.
192.168.0.3 - Reply received.
192.168.0.4 - Reply received.
192.168.0.5 - Reply received.
192.168.0.6 - Reply received.
192.168.0.7 - Reply received.
192.168.0.8 - Reply received.
192.168.0.9 - Reply received.
192.168.0.10 - Reply received.
Exit code: 0 , 0000h
'==========

I hope this gets you started.

mmcdonal
Reply With Quote