CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 1999
    Posts
    14

    how to detect an Internet connection ??

    i'd like to detect if there's an existing internet connection on a user's machine - machine could have a network card and/or a dialup connection or nothing. Tried to use GetInternetConnectedState() API on my machine (dialup connection ON, network card but no network) and it;'s telling me i have a LAN connection even when the dialup line is Off ! What's the kosher sure-fire way to determine if there's an internet connection alive on the local machine ? Thanks !


  2. #2
    Join Date
    May 1999
    Location
    Austin TX
    Posts
    31

    Re: how to detect an Internet connection ??

    Well one way would be to see if this machine has an IP address. If it is on a network it may have an IP address but still not be on the internet. The sure fire way would be to "ping" an internet site that will never go down, like Microsoft. If you get a response it is probably a good bet that you are on the internet.


  3. #3
    Join Date
    May 1999
    Posts
    19

    Re: how to detect an Internet connection ??

    In case the user isn't connected it will bring a pop-up Dialup window.



  4. #4
    Join Date
    Apr 1999
    Posts
    1

    Re: how to detect an Internet connection ??

    How can I avoid the pop-up Dialup window when checking for internet connection?


  5. #5
    Guest

    Re: how to detect an Internet connection ??

    How about --- InternetGetConnectedState ?? or is it the same thing

    DWORD lpdwFlags;//NTERNET_CONNECTION_MODEM|INTERNET_CONNECTION_LAN|INTERNET_CONNECTION_PROXY ;
    if( InternetGetConnectedState(&lpdwFlags ,0) == FALSE)
    // I got this code from ljp and it seems to work great for me.
    {
    AfxMessageBox("we are not on line");
    //not connected
    }
    else
    {
    AfxMessageBox("Internet Connection We are online ");
    //conected !
    }
    }


    GetHostbyName() works also but not good for NT and LAN connections it seems.
    True Pinging a known ISP is a proven method, But I can't understand RAS well enough.

    Regards
    Colin Davies
    [email protected]

    PS: please tell me if it doesn't work as I'll need to change my code.


  6. #6
    Join Date
    May 1999
    Posts
    17

    Re: how to detect an Internet connection ??


    int nI;
    BOOL bConnected = FALSE;
    DWORD dwRasBuffSize = sizeof( RASCONN ) * 5;
    DWORD dwStructWritten = 5;
    RASCONN sRasconn[5];
    RASCONNSTATUS sConnectionStatus;

    //Initialize our connection structure
    memset( sRasconn, 0, (sizeof( RASCONN ) * 5) );

    for( nI = 0; nI < 5; nI++ )
    sRasconn[nI].dwSize = sizeof( RASCONN );

    //Check for a connection to the internet
    RasEnumConnections( &sRasconn[0], &dwRasBuffSize, &dwStructWritten );

    //See if one of them is connected to the internet
    for( nI = 0; nI < (int) dwStructWritten; nI++ )
    {
    //Load in the connection data
    RasGetConnectStatus( sRasconn[nI].hrasconn,
    &sConnectionStatus );

    //If we are connected set the connected flag
    if( sConnectionStatus.rasconnstate == RASCS_Connected ||
    sConnectionStatus.rasconnstate == RASCS_OpenPort )
    bConnected = TRUE;

    }

    //Are we to start the server?
    if( bConnected )
    ...









    My code may not be completely accurate. It may think there is a connection to the internet when
    its really just a connection to some network.


  7. #7
    Join Date
    May 1999
    Posts
    19

    Re: how to detect an Internet connection ??

    First of all, rasenumconnection isn't supported by native win'95.

    Second, you have a function called rasconnected, which gives you the number and statistic for connected ras devices.

    The problem is, though, that we would like to detect also other cases, such as connection not via ras device. Another small problem you have meantioned, is that it will report local network connections, while we would like to get only internet.

    Ideas?



  8. #8
    Join Date
    May 1999
    Posts
    2

    Re: how to detect an Internet connection ??

    This function always returns true and always says it is a LAN connection. I tested it on a packard bell right out of the box with no netword card at all and no Dialup connection. It was running win 98. I also tested on basically all of the different combinations of Dial Up and LAN. My guess it that the body of the function looks something like
    {
    lpdwFlags = INTERNET_CONNECTION_LAN;
    return true;
    }

    I am having the same problem. I want to be able to check if a net connection is available. Is there any real way that anyone knows of that will work in NT 4.0/98/95? Prefferably using winInet ? I also have found that InternetAttemptConnect and InternetCheckConnection always return 0. All that I want to know is if the person can get out to the web.


  9. #9
    Join Date
    Dec 2001
    Posts
    2

    Re: how to detect an Internet connection ??

    Your code works perfect in Windows 2000. Under windows 98SE returns INTERNET_CONNECTION_LAN


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured