Results 1 to 16 of 16

Thread: [RESOLVED] [02/03] How do I use this PING class?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Resolved [RESOLVED] [02/03] How do I use this PING class?

    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?
    Attached Files Attached Files
    Last edited by jsun9; Mar 31st, 2006 at 10:57 AM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    Anyone?
    Click here to view the converted code.
    Last edited by jsun9; Sep 16th, 2004 at 10:42 AM.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    Interesting.. it gives the impression of working, but it always returns a number around 63 for me. If I do something like this:
    VB Code:
    1. Dim a As New clsPing
    2. Dim b(4) As Long
    3. a.Host = "66.94.231.99"
    4. b(1) = a.Ping()
    5. a.Host = "216.239.39.99"
    6. b(2) = a.Ping()
    7. a.Host = "66.94.231.99"
    8. b(3) = a.Ping()
    9. a.Host = "66.94.231.99"
    10. b(4) = a.Ping()
    11. MsgBox(b(1) & " | " & b(2) & " | " & b(3) & " | " & b(4))
    it returns 63 | 0 | 0 | 0
    If I click it twice, it returns 0 | 0 | 0 | 0
    What's up with that?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    bump

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    Maybe there is a better way to ping that's not posted on this forum?

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    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:
    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.
    Here's the code where it happens.
    VB Code:
    1. Array.Copy(ThisPacket.Data, 0, Buffer, iIndex, PingData)
    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.
    I'm calling the function like this:
    VB Code:
    1. Dim a As New clsPing
    2. a.PingHost("10.10.20.12", 32, 4, 2000)
    Any help in figuring this out would be greatly appreciated.
    Last edited by jsun9; Aug 3rd, 2004 at 12:35 PM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    Anyone out there use ping fro VB.Net? Want to shed some light on this subject?

  9. #9
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307
    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.
    "I'm Brian and so is my Wife"

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525
    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.

  11. #11
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    Re: How do I use this PING class?

    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
    VB Code:
    1. Dim a As New clsPing
    2. a.Host = "10.0.0.129"
    3. Dim b As Long = a.Ping()
    4. MsgBox(b)
    And it works once, but if Itry pinging the same ip again I just get 0.
    Anyone know whats wrong with the code, or any better ways to ping.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: How do I use this PING class?

    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.

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How do I use this PING class?

    Quote Originally Posted by jsun9
    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?

    I know this is an old thread, but I was looking for a class like this. I've corrected/modified the code...

    (Attached)

    Attached Files Attached Files

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: How do I use this PING class?

    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.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: How do I use this PING class?

    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:
    1. Imports System.Net.NetworkInformation
    2. Private Sub Whatever()
    3.    Dim ping As New Ping
    4.    Dim reply As PingReply = ping.Send(“216.109.112.135”)
    5.    
    6.    'Show the ping results
    7.    MessageBox.Show(reply.RoundtripTime.ToString("N"))
    8. End Sub
    Attached Files Attached Files

  16. #16
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [RESOLVED] [02/03] How do I use this PING class?

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width