Solved

Ping a website and check internet connection

Posted on 2013-11-18
7
280 Views
Last Modified: 2013-12-05
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 ?
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39659343
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 Function
End Module

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

Author Comment

by:isnoend2001
ID: 39659490
thanks  SStory
Don't need code to check the connection. only to wait until the check is done before the ping
0
 
LVL 25

Expert Comment

by:SStory
ID: 39660173
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:isnoend2001
ID: 39660236
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.

I am testing some other code now:

While mConnectionCheckDone = False
  DoEvents
    DoEvents
    Sleep (55)
Wend
mConnectionCheckDone = False
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39661182
That is NOT what you asked for.  Here is your quote
How can i make the ping wait until the internet connection is done and results entered into a list box

Checking for an Internet connection will take as long as you want to allow for a timeout when pinging something.
0
 

Author Closing Comment

by:isnoend2001
ID: 39696483
Thanks
0
 
LVL 25

Expert Comment

by:SStory
ID: 39698321
Other good ideas here.
http://stackoverflow.com/questions/1085045/check-whether-internet-connection-is-available-with-c-sharp

DNS lookup, then download a known txt file.

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question