-
Sep 1st, 2021, 04:25 AM
#1
Thread Starter
Addicted Member
[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
-
Sep 1st, 2021, 06:12 AM
#2
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
-
Sep 1st, 2021, 06:19 AM
#3
Thread Starter
Addicted Member
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.
-
Sep 1st, 2021, 10:20 AM
#4
Thread Starter
Addicted Member
Re: Fast Ping (non-blocking)
Any other suggestions or approach?
-
Sep 1st, 2021, 12:20 PM
#5
Re: Fast Ping (non-blocking)
Originally Posted by beic
... 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
-
Sep 1st, 2021, 12:54 PM
#6
Thread Starter
Addicted Member
Re: Fast Ping (non-blocking)
Originally Posted by Schmidt
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?
-
Sep 2nd, 2021, 04:04 AM
#7
Re: Fast Ping (non-blocking)
Originally Posted by beic
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
-
Sep 2nd, 2021, 05:34 AM
#8
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
-
Sep 2nd, 2021, 10:14 AM
#9
Re: Fast Ping (non-blocking)
Originally Posted by westconn1
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
-
Sep 2nd, 2021, 10:20 AM
#10
Thread Starter
Addicted Member
Re: Fast Ping (non-blocking)
Originally Posted by Schmidt
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.
-
Sep 3rd, 2021, 01:45 AM
#11
Hyperactive Member
Re: Fast Ping (non-blocking)
care to share your code. may help others in the future
-
Sep 3rd, 2021, 04:00 AM
#12
Thread Starter
Addicted Member
Re: Fast Ping (non-blocking)
Originally Posted by k_zeon
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|