Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to detect if Internet is online/offline

Posted on 2001-07-11
9
Medium Priority
?
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 152 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 2

Assisted Solution

by:MadYugoslav
MadYugoslav earned 148 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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