Solved

VB.net Ping class

Posted on 2010-09-06
8
577 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

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!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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