i have created a function that runs on my desktop that checks my website is up every 1/2 hour
The ping works very fast,and pouts the results in a listbox but now i want to check to be sure my internet connection is valid before the ping.The problem I have run into is the checking the internet connection takes a couple seconds.
How can i make the ping wait until the internet connection is done and results entered into a list box ?
Visual Basic Classic
Last Comment
SStory
8/22/2022 - Mon
SStory
Something like this should work:
Module Module1 'add as many known sites as you wish; those that are pingable if the internet is up Private InternetSites() As String = {"www.foxnews.com", "www.google.com", "www.yahoo.com", "www.expedia.com"} Const MAX_FAILURES_TO_PROVE_DOWN As Byte = 3 Sub Main() If My.Computer.Network.IsAvailable Then If InternetIsReachable() Then 'DO YOUR STUFF HERE End If End If End Sub Private Function InternetIsReachable() As Boolean Dim FailureCount As Short = 0 For Each Site As String In InternetSites If My.Computer.Network.Ping(Site) Then Return True Else FailureCount += 1 End If If FailureCount > MAX_FAILURES_TO_PROVE_DOWN Then Return False End If Next Return False End FunctionEnd Module
I haven't tested it yet and you'll need to use it from a Win form if you want a listbox.
isnoend2001
ASKER
thanks SStory
Don't need code to check the connection. only to wait until the check is done before the ping
SStory
My code will not return for your ping until it has checked.
I don't see the problem. You call it and it will try and try and until it gives a pass or fail. If it passes you can ping.
I want to know why the Ping has failed.
If i unplug from the internet and check if connected it takes a few seconds to time out
During that time it tries to ping which fails. Then I cannot determine why the ping fails.
As to where it fails you would need to do a tracert
That means see if your LAN interface is up, then ping LAN side of your router(s) and each hop until you ping a website. Wherever it fails is where to look.
Basically ICMP protocol.
Open in new window
I haven't tested it yet and you'll need to use it from a Win form if you want a listbox.