• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1125
  • Last Modified:

visual studio 2010 + getting ping latency from remote computer

I would like to get the ping information (latency) when I ping a remote computer.
0
mphillip85
Asked:
mphillip85
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
If you are talking about VB.NET, that MSDN article has some source code, but only for C#.  Here is the VB.NET translation:


Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Text

Namespace Examples.System.Net.NetworkInformation.PingTest
	Public Class PingExample
		' args[0] can be an IPaddress or host name.
		Public Shared Sub Main(args As String())
			Dim pingSender As New Ping()
			Dim options As New PingOptions()

			' Use the default Ttl value which is 128,
			' but change the fragmentation behavior.
			options.DontFragment = True

			' Create a buffer of 32 bytes of data to be transmitted.
			Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
			Dim buffer As Byte() = Encoding.ASCII.GetBytes(data)
			Dim timeout As Integer = 120
			Dim reply As PingReply = pingSender.Send(args(0), timeout, buffer, options)
			If reply.Status = IPStatus.Success Then
				Console.WriteLine("Address: {0}", reply.Address.ToString())
				Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime)
				Console.WriteLine("Time to live: {0}", reply.Options.Ttl)
				Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment)
				Console.WriteLine("Buffer size: {0}", reply.Buffer.Length)
			End If
		End Sub
	End Class
End Namespace

Open in new window

0
 
mphillip85Author Commented:
how do i make the source (127.0.0.1) different.  I want to test a ping from a changing source and destination.  
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Bob LearnedCommented:
You don't have control over the source.  You would have to run the test from that machine.

The Ping class is a wrapper around the IcmpSendEcho2 command:

<DllImport("iphlpapi.dll", SetLastError:=True)> _
Friend Shared Function IcmpSendEcho2(ByVal icmpHandle As SafeCloseIcmpHandle, ByVal [Event] As SafeWaitHandle, ByVal apcRoutine As IntPtr, ByVal apcContext As IntPtr, ByVal ipAddress As UInt32, <[In]> ByVal data As SafeLocalFree, ByVal dataSize As UInt16, ByRef options As IPOptions, ByVal replyBuffer As SafeLocalFree, ByVal replySize As UInt32, ByVal timeout As UInt32) As UInt32
End Function

That function only specifies destination addresses, and not source addresses.

IcmpSendEcho2 Function
http://msdn.microsoft.com/en-us/library/aa366051(VS.85).aspx
0
 
mphillip85Author Commented:
what can i do to change the source.  is that a add-on for vb that will give me that flexibility?

there are utilities that you can set source and destination.  This is what my goal is.

Thanks
0
 
Bob LearnedCommented:
I believe that the difficulty is at the operating system level.  The assumption is that the source is already known, so it is not an argument.  There are no add-ons, or arguments that you can specify with IcmpSendEcho2 that will allow you to do that, that I know of.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now