Click to See Complete Forum and Search --> : how to detect an Internet connection ??


Jerome
April 4th, 1999, 05:36 PM
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 !

Merlin
April 8th, 1999, 06:06 PM
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.

Ran
April 9th, 1999, 08:06 PM
In case the user isn't connected it will bring a pop-up Dialup window.

Koen VdH
April 23rd, 1999, 02:40 AM
How can I avoid the pop-up Dialup window when checking for internet connection?

April 23rd, 1999, 05:07 AM
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
taxpaid@bigfoot.com

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

Chris M.
May 12th, 1999, 09:32 AM
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.

Ran
May 15th, 1999, 06:09 AM
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?

Brian Lynch
May 25th, 1999, 01:38 PM
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.

Lucianus
December 17th, 2001, 09:05 AM
Your code works perfect in Windows 2000. Under windows 98SE returns INTERNET_CONNECTION_LAN