Solved

How to detect if Internet is online/offline

Posted on 2001-07-11
9
368 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
This video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now