Am I connected to the Internet?

Is there a good way to programmatically determine if I am connected to the internet

Answer this question

Am I connected to the Internet?

  • Andrew Hogg

    I have no experience with this but a quick peek into the help system gave me the item
    <strong>"Managing Connections"</strong> which redirects to the class <strong>ServicePointManager</strong> for this issue

  • gsuchi

    Yeah you can read more about the above here:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconmanagingconnections.asp

  • CourtJesterG

    Hmmm, it looks like ServicePoint requires a URL to connect to.  I don't want to make a connection to a particular web site.  I just want to know if I am connected to the internet. 

    If it helps, here's the situation.  The app is about to make a call over the internet.  If no connection is available, an exception is thrown.  So, before I make the internet call, I want to check to see if the computer has an internet connection.   If there is a connection, then I'll make the internet call.  If there is no connection, then I won't.  Here's the psuedocode: 

    if IsConnected 
      make internet call 
    else 
      display error message 
    end if 

    But if all that ServicePoint does is make an internet connection to a URL, then I might as well not bother with ServicePoint and just catch the exception.  Psuedocode: 

    try 
      make intenet call 
    catch 
      display error message 
    end try 

    So, let me redefine my original question: Is there a way to check to see if the computer is connected to the internet without actually hitting some web site   If not, I might as well just catch the exception. 

    Thanks. 

  • Am I connected to the Internet?