Solved

How to detect if Internet is online/offline

Posted on 2001-07-11
9
389 Views
Last Modified: 2013-12-03
Hi to all,

I'm going to  write a Programm, with MS VC++ 6.0 under WIN NT and I want to know how I can detect if an Internet session is online / offline. It must work with all connection type ( modem, lan, proxy etc.)

How can i do this ??

thanks for your time and thanks in advance

PhilMa

0
Comment
Question by:PhilMa
9 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 6272886
That depends on what you define as "internet session".

What do you really want to know?  

If the question is: "can I open a connection to X?" then there are several ways of doing that but they all involve testing the connection and seeing if it works.

If the supposed question is: "am I connected to the internet?" then the answer is no.  What is the internet anyway?  It's not a thing to be connected to.  Your computer is either connected to a local network via a LAN card or to a service provider via a modem, etc.  So you're back to the first part of this comment.  All you can do is test various sites and see if connections can be made.

In Windows there is the InternetGetConnectedState function in WININET.DLL but it's use can be highly confusing to those who don't understand what it's saying.  All it knows is if a network connection is potentially available, NOT it a particular site can be reached.
0
 
LVL 86

Accepted Solution

by:
jkr earned 38 total points
ID: 6273643
'InternetGetConnectedState()' is the API of choice - see http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/wininet/reference/functions/internetgetconnectedstate.asp and
http://support.microsoft.com/support/kb/articles/Q242/5/58.ASP ('HOWTO: Detecting If You Have
a Connection to the Internet') wich provides a full-featured example.
0
 

Author Comment

by:PhilMa
ID: 6275748
Hi jhance,

Thanks for your answer, I want to know if a network connection is online or offline.

If I understand you right, InternetGetConnectedState() checks only if the computer is equiped with a network card or a modem  to connect to the internet via LAN or an Service provider.

How can i detcect, if i can reach a site? Maybe you have an example

PhilMa
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Assisted Solution

by:MadYugoslav
MadYugoslav earned 37 total points
ID: 6275927
// You need to pass as arguments sitem name (for example
// "www.experts-exchange.com") and port number for
// connection (for example HTTP port is 80)

BOOL TestFunction(char* Site, UINT Port)
{
   BOOL RetFlag=FALSE;
   CSocket* SocketObject=new(CSocket);
   if( SocketObject->Create() )
      RetFlag=SocketObject->Connect((char* )LPCTSTR(Site), Port);
   SocketObject->Close();
   delete(SocketObject);
   return(RetFlag);
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 6278023
Well, it wasn't jhance, it was me :o)

>>If I understand you right, InternetGetConnectedState()
>>checks only if the computer is equiped with a
>>network card or a modem  to connect to the internet via
>>LAN or an Service provider


From the docs:

"InternetGetConnectedState
BOOL InternetGetConnectedState(
    OUT LPDWORD lpdwFlags,
    IN DWORD dwReserved
);

Retrieves the connected state of the local system.

Returns TRUE if there is an Internet connection, FALSE otherwise. "

IT checks if there's a connection through either a modem or a NIC, not whether the system is equipped with that (well, you could assume that if there's a connection through a NIC, that the system is equipped with one :o)
0
 
LVL 86

Expert Comment

by:jkr
ID: 10582722
'InternetGetConnectedState()' - what should I add :o)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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