Advertisement
rg443

vb.net icmp traceroute

Dec 15th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.26 KB | None | 0 0
  1. Imports System.Net.NetworkInformation
  2. Imports System.Net
  3.  
  4. Module Module1
  5.  
  6.     Sub Main()
  7.         Dim p As New Ping()
  8.         Dim ttl As Integer = 0
  9.         Dim host As IPAddress
  10.         Dim response As PingReply = p.Send("www.google.com")
  11.         Dim target As IPAddress = response.Address
  12.         Dim buffer(1) As Byte
  13.         Dim watch As New Stopwatch()
  14.  
  15.         Do
  16.             Dim options As PingOptions
  17.  
  18.             ttl += 1
  19.             options = New PingOptions(ttl, True)
  20.  
  21.             Console.Write("{0,3}  ", ttl)
  22.  
  23.             For i As Integer = 1 To 3
  24.                 watch.Restart()
  25.                 response = p.Send(target.Address, 5000, buffer, options)
  26.                 watch.Stop()
  27.                 host = response.Address
  28.  
  29.                 If response.Status = IPStatus.TimedOut Then
  30.                     Console.Write("  *    ")
  31.                 Else
  32.                     Console.Write("{0,3} ms  ", watch.ElapsedMilliseconds)
  33.                 End If
  34.             Next
  35.  
  36.             If response.Status = IPStatus.TimedOut Then
  37.                 Console.WriteLine("Request timed out.")
  38.             Else
  39.                 Console.WriteLine("{0}", host.ToString())
  40.             End If
  41.         Loop Until target.Equals(host)
  42.  
  43.     End Sub
  44.  
  45. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement