Pinging IP

  • Thread starter Thread starter Vjay77
  • Start date Start date
* (e-mail address removed)-spam.invalid (Vjay77) scripsit:

In C#:

<http://www.c-sharpcorner.com/network/ping.asp>

I spent most of the morning trying to find a decent .NET VB solution.
The C# that keeps being mentioned is no use to me. Eventually, and
sorry I forget where but it came from a few sources that I pieced
together, I worked my way towards this. Excuse the formatting.

Function isAlive(ByVal host As String) As Boolean
Dim objStatus As ManagementObject
Dim objPing As New SelectQuery("Select StatusCode from
Win32_PingStatus " & _
"WHERE Address = '" & host & "' and statuscode = 0")
Dim Search As New ManagementObjectSearcher(objPing)
' because the hostname is unique, and statuscode=0 means "success",
we can just say
isAlive = (Search.Get.Count = 1)
objPing = Nothing
objStatus = Nothing
Search = Nothing
End Function

msgbox isAlive("www.microsoft.com") - will return a nice "true" -
unless some worm takes the site down :P

Pasting here for the benefit of the google groups, hope it saves
someone a morning's effort. My problem turned out to be a spot of
ignorance of the WMI classes. I just didn't think for a minute there
would be one for ping, despite using most of the others on a daily
basis :)

Search terms in google: "win32_pingstatus managementobject" will bring
up a few likely pages.

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_pingstatus.asp
http://www.serverwatch.com/tutorials/print.php/1571771
 
Back
Top