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
Solved

VB.net Ping class

Posted on 2010-09-06
8
576 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
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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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