Solved

VB.net Ping class

Posted on 2010-09-06
8
582 Views
Last Modified: 2012-05-10
Hi,
Can i please have some help with regards to ping a ip address or host name for example 10.0.0.1 or www.microsoft.com?
I need to create a simple class that i can pass it an ip address and it then returns the result. I would like to then thread it so i can do multiple pings. I am not to sure wha tthe difference is between using ping in asyncronous or syncronous

thanks
0
Comment
Question by:CraigLazar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 200 total points
ID: 33612366
0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 33612371
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 33612458
Hi,
thanks for the links, i have already tried those but battling to get them to work.
in vb.net
0
Independent Software Vendors: 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 4

Author Comment

by:CraigLazar
ID: 33612499
this is what i have at the moment, which is returning a time out  for reply object
Button on a form

Dim meas As New PingExample
Dim xme(2) As String
xme(0) = "www.microsoft.com
xme(1) = "www.google.com
PingExample.Main(xme)
 
Class

Public Class PingExample
' args[0] can be an IPaddress or host name.
Public Shared Sub Main(ByVal 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
0
 
LVL 11

Assisted Solution

by:lenordiste
lenordiste earned 200 total points
ID: 33613491
everything is fine with your code, it's just that your test data is not: "www.microsoft.com" does not reply to the ping.

"www.google.com" does however so you can test this one:
PingExample.Main("www.google.com")
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 33614360
Here is my ping function.
Have a try...

 Public Function PingRemoteHost(ByVal HostAddress As String, Byval Arguments) As String
        Dim PingReply As String = String.Empty
        Using pingProcess As New Process
            Dim startInfo As New ProcessStartInfo("ping")
            startInfo.RedirectStandardInput = True
            startInfo.RedirectStandardOutput = True
            startInfo.UseShellExecute = False
            startInfo.CreateNoWindow = True
            startInfo.WindowStyle = ProcessWindowStyle.Hidden
            startInfo.Arguments = HostAddress & " " & Arguments

            pingProcess.StartInfo = startInfo
            pingProcess.Start()

            PingReply = pingProcess.StandardOutput.ReadToEnd

            pingProcess.WaitForExit()
            pingProcess.Close()

        End Using
        Return PingReply
End Function

Open in new window

0
 
LVL 41

Expert Comment

by:graye
ID: 33617552
Hang on... I think lenordiste has nailed it....  The microsoft web site (and countless many others) filter ping requests at the firewall.   So, there's nothing wrong with your code.
...uh well, perhaps other than the fact you pass an array and only perform a ping on the first element in the array.
0
 
LVL 4

Author Closing Comment

by:CraigLazar
ID: 33635502
thanks guys for the help
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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