Results 1 to 12 of 12

Thread: [RESOLVED] Fast Ping (non-blocking)

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Resolved [RESOLVED] Fast Ping (non-blocking)

    Hi there,

    Could anyone help me with the Ping function?

    I wish to Ping my whole local network "fast" as possible.

    I tried with different API combinations like: inet_addr, GetRTTAndHopCount and IcmpSendEcho, but it's lagging and freezing the Form and it's too slow scanning the network.

    My simple loop code example:

    Code:
    Dim itCnt As Integer
    Dim lgTimeOms as Long
    Dim stIpRng As String
    Dim stIpAddr As String
    
    lgTimeOms = 100
    
    stIpAddr = ""
    stIpRng = "192.168.0."
    
    For itCnt = 1 To 255
     stIpAddr = stIpRng + CStr(itCnt)
     If Ping(stIpAddr, lgTimeOms) = True Then
      List1.AddItem stIpAddr
     End If
     stIpAddr = ""
    Next itCnt
    Note: I already did this all with ARP and it's working very fast, but unfortunately for me, I forgot that the ARP table will be cleared/lost after every computer restart, upssss.

    Thank you,

    Kind regards,
    Viktor

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fast Ping (non-blocking)

    have a look at the code posted by olaf
    https://www.vbforums.com/showthread....=1#post4476707

    i also have some similar code (no idea where it came from originally) that uses waitforsingleobject with a time out for each ip address
    in either case som significant testing should be done to confirm correct results
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Fast Ping (non-blocking)

    Thank you, I already tried that solution, the problem is that the mentioned code only shows 3 of 10 IP addresses from the local network.

  4. #4

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Fast Ping (non-blocking)

    Any other suggestions or approach?

  5. #5
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by beic View Post
    ... the problem is that the mentioned code only shows 3 of 10 IP addresses from the local network.
    There's a Const within that function, which is currently at 100 (millisec).

    Increasing this value to e.g. 500 (msec) could help, detecting the yet missing IPs.

    Olaf

  6. #6

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by Schmidt View Post
    Increasing this value to e.g. 500 (msec) could help, detecting the yet missing IPs.
    With 500ms is better, but would vary every time calling the function, with 1000ms is great, but again sometimes some IP addresses will be left out?

  7. #7
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by beic View Post
    With 500ms is better, but would vary every time calling the function, ...
    That's normal...

    Then perhaps calling the function "3-5 times in a loop" (then maybe with 350msec) will produce better results
    (merging the IPs "not yet captured from previous inner-loop-results" into a final "target-collection").

    Olaf

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Fast Ping (non-blocking)

    seems to be a far from perfect solution
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by westconn1 View Post
    seems to be a far from perfect solution
    ICMP itself is not a "reliable protocol" (the transport can fail for a whole lot of different reasons).

    That's why a "ping-command" on the console is always starting a "whole sequence of pings" -
    because "just a single ping" has a quite high probability, to not come back within a given time, due to "those multiple reasons".

    <shrug>

    Olaf

  10. #10

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by Schmidt View Post
    That's normal...
    Then perhaps calling the function "3-5 times in a loop" (then maybe with 350msec) will produce better results
    (merging the IPs "not yet captured from previous inner-loop-results" into a final "target-collection").
    But, I figured out something really good thing, I left out from your code the "Collection" part, only Ping left (one time loop needed of 1000ms).

    So, after I realized that your Ping function with Echo Reply will recreate the ARP table on current computer and I could easily fetch data from it.

    And now I got full network scan with IP, MAC Addresses and with Host Names under 4-7 seconds with Device Name + MAC Address Vendor parsing.

  11. #11
    Hyperactive Member
    Join Date
    Nov 2011
    Posts
    498

    Re: Fast Ping (non-blocking)

    care to share your code. may help others in the future

  12. #12

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    150

    Re: Fast Ping (non-blocking)

    Quote Originally Posted by k_zeon View Post
    care to share your code. may help others in the future
    There is really nothing to share, you just combine these two codes together from the posts:

    https://www.vbforums.com/showthread....=1#post4476707
    https://www.vbforums.com/showthread....-the-ARP-table
    Last edited by beic; Sep 3rd, 2021 at 04:01 AM. Reason: typo

Tags for this Thread

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