I'm trying to use this ping class, but I have no idea how to set it up. I added it as a class, and the function is public, but I cannot call it on my form like I could in VB6. How do I use this class to ping a host or ip address?
Printable View
I'm trying to use this ping class, but I have no idea how to set it up. I added it as a class, and the function is public, but I cannot call it on my form like I could in VB6. How do I use this class to ping a host or ip address?
Anyone?
Click here to view the converted code.
Instance it:
Dim a As New clsPing
You set the host
a.Host = "127.0.0.1"
You ping
dim b as Long = a.Ping()
Done
Add this to the class because it is incomplete
Public Enum ICMPType
EchoReply = 0
Unreachable = 3
Echo = 8
End Enum
Interesting.. it gives the impression of working, but it always returns a number around 63 for me. If I do something like this:
it returns 63 | 0 | 0 | 0VB Code:
Dim a As New clsPing Dim b(4) As Long a.Host = "66.94.231.99" b(1) = a.Ping() a.Host = "216.239.39.99" b(2) = a.Ping() a.Host = "66.94.231.99" b(3) = a.Ping() a.Host = "66.94.231.99" b(4) = a.Ping() MsgBox(b(1) & " | " & b(2) & " | " & b(3) & " | " & b(4))
If I click it twice, it returns 0 | 0 | 0 | 0
What's up with that?
bump
Maybe there is a better way to ping that's not posted on this forum?
Alright, here is some other code that seems a bit more promising as it tries to duplicate the ping command built into windows. It doesn't quite work and I'm trying to figure out why. It was originally written in C# but was converted to VB.Net using the Microsoft C# to VB.Net converter. After some other modifications I was able to get the program to compile without any errors. You can view the code here.
I'm getting this error under the "Serialize" function:
Here's the code where it happens.Quote:
An unhandled exception of type 'System.ArgumentException' occurred in Ping.exe
Additional information: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
That line really makes no sense since it's trying to stuff 32 bytes of data into a 33 byte array starting at index 14? I'm guessing something is missing somewhere else, or something didn't get converted.VB Code:
Array.Copy(ThisPacket.Data, 0, Buffer, iIndex, PingData)
I'm calling the function like this:
Any help in figuring this out would be greatly appreciated.VB Code:
Dim a As New clsPing a.PingHost("10.10.20.12", 32, 4, 2000)
Anyone out there use ping fro VB.Net? Want to shed some light on this subject?
This for your use or for a company project?
If it's for a company project I'd recommend getting them to fork out for the nSoftware Red Carpet Solution.
Details can be found here .
Their IP* Works solution has been a god-send for me at work. I use it to ping clients on our network, run remote commands on our UNIX boxes etc, all from my VB .NET app.
Well, this isn't a top priority project (hence the sporatic posts), so there's no way I'd pay for this. Besides, it seems like there isn't any good VB.Net source for this. I would think this would be beneficial not only for myself, but for the community.
If someone has come across a working piece of code, please point it out! Thanks.
Hi all ,
Am hoping someone might be able to shed some light on this, as I would also like to be able to ping.
Have copied ping.zip code into my project. And it works
I do
And it works once, but if Itry pinging the same ip again I just get 0.VB Code:
Dim a As New clsPing a.Host = "10.0.0.129" Dim b As Long = a.Ping() MsgBox(b)
Anyone know whats wrong with the code, or any better ways to ping.
Oliver1 - for the life of me I cannot figure this one out. I've looked all over the web for something that works and I cannot find anything. But that was a while ago and maybe something else has showed up now? If you do find anything on it please post it here.
Quote:
Originally Posted by jsun9
I know this is an old thread, but I was looking for a class like this. I've corrected/modified the code...
(Attached)
:afrog:
The code works identically to the other code on this forum? You can ping once, you get some erroneous number then you can't ping after that.
Well, someone at work figured it out for me. He's using the same class as I've posted earlier. I've attached for everyone else. Enjoy!
FYI: The attachment is in vb.net 2003. If you're using .net 2005 then everything is built in for you and you don't really need to do anything:
VB Code:
Imports System.Net.NetworkInformation Private Sub Whatever() Dim ping As New Ping Dim reply As PingReply = ping.Send(“216.109.112.135”) 'Show the ping results MessageBox.Show(reply.RoundtripTime.ToString("N")) End Sub
You can also check out my codebank for "Automate Command Prompt and Redirect Output to Application", and just call ping from there, without even opening a command window, and have the result text available to you in your application...