Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

How to detect if Internet is online/offline

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
PhilMa
Asked:
PhilMa
2 Solutions
 
jhanceCommented:
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
 
jkrCommented:
'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
 
PhilMaAuthor Commented:
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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
MadYugoslavCommented:
// 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
 
jkrCommented:
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
 
jkrCommented:
'InternetGetConnectedState()' - what should I add :o)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now