Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• About the product
• Download
• Sample projects:
Using with VB
Using with ASP
Using with VBScript
Using with MS Access
Using with C#
• Support Forum
OISV - Organization of Independent Software Vendors - Contributing Member
ICMP Component - Samples (Using with Visual Basic)

Sending e-mail, using OstroSoft ICMP Component (OSICMP.dll)
Download project source code

Minimum requirements: Visual Basic 5, OSICMP.dll*
* If you don't have OstroSoft ICMP Component, see installation instructions

1. In Visual Basic create a new Standard EXE project
2. Add a Reference to OSICMP
3. Add controls to the form: VB.CommandButton cmdTraceroute, VB.CommandButton cmdPing, VB.TextBox txtOutput (MultiLine = True), VB.TextBox txtHost
4. Enter the following code:

Option Explicit

Private Sub cmdPing_Click()
  Dim oPing As New OSICMP.Ping
  Dim i As Integer 'request counter
  Dim s As String
  
On Error GoTo err_handler:
 
  For i = 0 To 3
    oPing.Send txtHost.Text
    
    If i = 0 Then
      If txtHost.Text <> oPing.IP Then _
        s = txtHost.Text & " [" & oPing.IP & "]" Else s = txtHost.Text
      txtOutput.Text = "Pinging " & s & " with " & _
        oPing.PacketSize & " bytes of data:" & vbCrLf & vbCrLf
    End If
    
    txtOutput.Text = txtOutput.Text & "Reply from " & _
      oPing.IP & ": bytes=" & oPing.PacketSize & " time=" & _
      oPing.RoundTripTime & "ms TTL=" & oPing.TTL & vbCrLf
    txtOutput.Refresh
    
    oPing.Sleep 1000
  Next
  
  txtOutput.Text = txtOutput.Text & vbCrLf & "complete"
  Exit Sub
  
err_handler:
  txtOutput.Text = "Error " & Err.Number & ": " & Err.Description
End Sub

Private Sub cmdTraceroute_Click()
  Dim oTraceroute As New OSICMP.Traceroute
  Dim i As Integer 'request counter
  Dim j As Integer 'hop counter
  Dim s As String
  Dim bTimeout As Boolean
  Dim sHopIP As String
  
On Error GoTo err_handler:
  txtOutput.Text = ""
  For j = 1 To 30 'limit tracing to 30 hops
    sHopIP = "request timed out"
    For i = 1 To 3 '3 requests per hop
      bTimeout = False
      oTraceroute.Send txtHost.Text, , , j
      
      If i = 1 Then
        If j = 1 Then
          If txtHost.Text <> oTraceroute.IP Then _
            s = txtHost.Text & " [" & oTraceroute.IP & "]" Else s = txtHost.Text
          txtOutput.Text = "Tracing route to " & s & vbCrLf & _
            "over a maximum of 30 hops:" & vbCrLf & vbCrLf
        End If
        txtOutput.Text = txtOutput.Text & j & "    "
      End If
      
      If bTimeout Then
        txtOutput.Text = txtOutput.Text & "   *   "
      Else
        txtOutput.Text = txtOutput.Text & "    " & oTraceroute.RoundTripTime & " ms"
        If sHopIP = "request timed out" Then sHopIP = oTraceroute.HopIP
      End If
      txtOutput.Refresh
    Next
    txtOutput.Text = txtOutput.Text & "  " & sHopIP & vbCrLf
    If oTraceroute.IP = sHopIP Then
      txtOutput.Text = txtOutput.Text & vbCrLf & "Trace complete." & vbCrLf
      Exit For
    End If
    oTraceroute.Sleep 1000
  Next
  
  If oTraceroute.IP <> sHopIP Then _
    txtOutput.Text = txtOutput.Text & vbCrLf & "Host unreachable." & vbCrLf
  Exit Sub
  
err_handler:
  If Err.Number = 11010 Then 'timeout
    bTimeout = True
    Err.Clear
    Resume Next
  End If
  
  txtOutput.Text = "Error " & Err.Number & ": " & Err.Description
End Sub

Copyright © 1996-2010 OstroSoft. All rights reserved. info@ostrosoft.com