Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

visual studio 2010 + getting ping latency from remote computer

Posted on 2010-09-07
6
Medium Priority
?
1,080 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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Understanding FTPS File transfer is a common requirement in most Enterprises. While there are numerous ways to get a file from Point A to Point B over a network, perhaps the most common method still in use is FTP – File Transfer Protocol. FTP is …
Please see preceding article here: http://www.experts-exchange.com/Networking/Operating_Systems/A_11209-Root-Bridge-Election.html Figure 1 After Root Bridge has been elected, then what?..... Let's start by defining a Root Port in la…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

927 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