Solved

visual studio 2010 + getting ping latency from remote computer

Posted on 2010-09-07
6
1,026 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
Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…

914 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

13 Experts available now in Live!

Get 1:1 Help Now