Solved

VB.net Ping class

Posted on 2010-09-06
8
566 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

20 Experts available now in Live!

Get 1:1 Help Now