Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PINGing a machine and capturing the response 2

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
GB
Does anyone know a little script to be able to ping a machine and pickup the response?

Thanks,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
FAQ222-607

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Or
Code:
[blue]Public Sub vbPing(sTarget As String)

    Dim cPingResults As Object    'collection of instances of Win32_PingStatus class
    Dim oPingResult As Object    'single instance of Win32_PingStatus class
    Dim strMsg As String
    
    
    Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + sTarget + "'")

    For Each oPingResult In cPingResults
        strMsg = ""
        If oPingResult.StatusCode = 0 Then
            If LCase(sTarget) = oPingResult.ProtocolAddress Then
                strMsg = strMsg & sTarget & " is responding" & vbCrLf
            Else
                strMsg = strMsg & sTarget & " (" & oPingResult.ProtocolAddress & ") is responding" & vbCrLf
            End If
            strMsg = strMsg & "Bytes = " & oPingResult.BufferSize & vbCrLf
            strMsg = strMsg & "Time (ms) = " & oPingResult.ResponseTime & vbCrLf
            strMsg = strMsg & "TTL (s) = " & oPingResult.ResponseTimeToLive
        Else
            strMsg = strMsg & sTarget & " is not responding"
        End If
    Next
    MsgBox strMsg, vbOKOnly, "Pinging " & sTarget

End Sub
[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top