Solved

How to detect if Internet is online/offline

Posted on 2001-07-11
9
374 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

10 Experts available now in Live!

Get 1:1 Help Now