Solved

visual studio 2010 + getting ping latency from remote computer

Posted on 2010-09-07
6
1,021 Views
Last Modified: 2012-05-10
I would like to get the ping information (latency) when I ping a remote computer.
0
Comment
Question by:mphillip85
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 33625121
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 33625527
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
 

Author Comment

by:mphillip85
ID: 33639407
how do i make the source (127.0.0.1) different.  I want to test a ping from a changing source and destination.  
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 33640687
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
 

Author Comment

by:mphillip85
ID: 33640789
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33640934
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now