[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
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
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.
Re: Fast Ping (non-blocking)
Any other suggestions or approach?
Re: Fast Ping (non-blocking)
Quote:
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
Re: Fast Ping (non-blocking)
Quote:
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?
Re: Fast Ping (non-blocking)
Quote:
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
Re: Fast Ping (non-blocking)
seems to be a far from perfect solution
Re: Fast Ping (non-blocking)
Quote:
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
Re: Fast Ping (non-blocking)
Quote:
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.
Re: Fast Ping (non-blocking)
care to share your code. may help others in the future
Re: Fast Ping (non-blocking)
Quote:
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