Ping routine

DSGarcia

Member
Joined
Sep 20, 2005
Messages
5
Location
Texas
Programming Experience
10+
I am trying to write a routine to Ping an IP address. It is designed to be in a continuous loop so I can jiggle network connections and wires to isolate an occasional communication problem that occurs from time to time (due to, I think, a vibration problem).

The GetRTTAndHopCount call I am using is not working as I think it should. I have a valid address and a normal ping works with the address. The code is written in VB.NET 2003. If there is another method (including a way to specify the record length of the ping, I would appreciate it).

Below is the code I am using:

Public Sub TestLoop()
Dim lIPadr As Long
Dim lHopsCount As Long
Dim lRTT As Long
Dim lMaxHops As Long = 20
Dim lResult As Long
Dim attempts As Long
Dim failures As Long
Dim IPAddress As String = "192.168.1.3"

lIPadr = inet_addr(IPAddress)
If lIPadr > 0 Then
Try
attempts = 0
failures = 0
status = 1
While (status)
lResult = GetRTTAndHopCount(lIPadr, lHopsCount, lMaxHops, lRTT)
If lResult <> 1 Then
failures = failures + 1
Beep()
End If
attempts = attempts + 1
End While
MsgBox("End Test, " & attempts & " attempts (" & failures & " failures)")
Catch ex As Exception
End Try
Else
MsgBox("Invalid IP Address", MsgBoxStyle.Critical)
End If
End Sub
 
You're using VB6 API declarations. In VB.NET you use Integer values with API functions, NOT Long values.

Also, are you aware of the Ping class in the .NET Framework? I don't know if it will do everything you want but you should check it out.
 
I changed the variables to Integers and it now works. I had received the code from someone and blindly entered it without thinking VB.NET is different.

Is there a way to shorten the timeout so a failure does not take so long to detect? The network is all local and will have a fast response when successful.
Thanks,
Dale
 
Last edited:
Back
Top