Ping using COMate
Posted: Fri Feb 13, 2009 9:57 pm
Using srod's COMate (with WMI), heres how to ping an address without using ping 

Code: Select all
IncludePath "..\..\"
XIncludeFile "COMate.pbi"
Procedure.s Ping_Status_Code(pingcode.i)
Select pingcode
Case 0
Ping_Stat$ = "Success"
Case 11001
Ping_Stat$ = "Buffer Too Small"
Case 11002
Ping_Stat$ = "Destination Net Unreachable"
Case 11003
Ping_Stat$ = "Destination Host Unreachable"
Case 11004
Ping_Stat$ = "Destination Protocol Unreachable"
Case 11005
Ping_Stat$ = "Destination Port Unreachable"
Case 11006
Ping_Stat$ = "No Resources"
Case 11007
Ping_Stat$ = "Bad Option"
Case 11008
Ping_Stat$ = "Hardware Error"
Case 11009
Ping_Stat$ = "Packet Too Big"
Case 11010
Ping_Stat$ = "Request Timed Out"
Case 11011
Ping_Stat$ = "Bad Request"
Case 11012
Ping_Stat$ = "Bad Route"
Case 11013
Ping_Stat$ = "TimeToLive Expired Transit"
Case 11014
Ping_Stat$ = "TimeToLive Expired Reassembly"
Case 11015
Ping_Stat$ = "Parameter Problem"
Case 11016
Ping_Stat$ = "Source Quench"
Case 11017
Ping_Stat$ = "Option Too Big"
Case 11018
Ping_Stat$ = "Bad Destination"
Case 11032
Ping_Stat$ = "Negotiating IPSEC"
Case 11050
Ping_Stat$ = "General Failure"
Default
Ping_Stat$ = "Unknown"
EndSelect
ProcedureReturn Ping_Stat$
EndProcedure
Procedure.s PING_Info(ping_address.s)
Define.COMateObject objWMIService, PINGInfo
sysPINGInfo.COMateEnumObject
strComputer.s = "."
strTarget$ = ping_address
objWMIService = COMate_GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
If objWMIService
sysPINGInfo = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_PingStatus Where Address= $0027" + strTarget$ +"$0027')")
If sysPINGInfo
PINGInfo = sysPINGInfo\GetNextObject()
While PINGInfo
PING_StatusCode$ = Ping_Status_Code(PINGInfo\GetIntegerProperty("StatusCode"))
PING_ProtocolAddress$ = PINGInfo\GetStringProperty("ProtocolAddress")
PING_ResponseTime$ = Str(PINGInfo\GetIntegerProperty("ResponseTime"))
PING_ResponseTimeToLive$ = Str(PINGInfo\GetIntegerProperty("ResponseTimeToLive"))
PING_Get_Info$ = "Ping Status: " + PING_StatusCode$ + " Protocol Address: " + PING_ProtocolAddress$ + " Response Time (ms): " + PING_ResponseTime$ + " Response Time To Live (ms): " + PING_ResponseTimeToLive$
PINGInfo\Release()
PINGInfo = sysPINGInfo\GetNextObject()
Wend
sysPINGInfo\Release()
EndIf
objWMIService\Release()
Else
MessageRequester("Error", "PINGInfoInfo")
EndIf
ProcedureReturn PING_Get_Info$
EndProcedure
Debug PING_Info("www.yahoo.com")