Check whether a PC has internet access

Posted on 2010-08-30
Last Modified: 2012-05-10
Any advice on how I'd check if the local system has internet access?

This needs to be compatible with 'standard' Windows operating systems, e.g. 32-bit, Win 95, 98, ME, XP, Vista, 7.

Thanks in advance.
Question by:rfwoolf
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
  • 3
  • 2
  • 2
  • +4
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33556887
win95 ?
uh oh ... get out of there !
btw, you missed win3.1

you could use a webbrowser and open
and then check if the document loads

off course there is the possibility your app gets blocked by the firewall
LVL 14

Assisted Solution

by:Pierre Cornelius
Pierre Cornelius earned 100 total points
ID: 33556936
The best way is to check if you have access to a specific internet resource. E.g. try to ping google or if you know the resource you will be accessing try that one instead.
LVL 13

Author Comment

ID: 33556990
Thanks guys..
I saw in another PAQ:
...the solution by HillGroover: a way to ping an address and it returns a boolean result.
This seems to be in line with what I'm looking for, but it's not easy to go and test it on multiple operating systems and with PCs with dialup etc..

Let me know if you have any ideas to top that solution, or if you foresee any problems.

'if you know the resource you will be accessing try that one instead.'
Not sure on what you mean by resource.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 25

Expert Comment

ID: 33556998
You could use Indy components to do that

TIDIPWatch :
Determines the online status and IP addresses for a computer.

* property IsOnline: Boolean;
IsOnline is a read-only Boolean property used to identify the current online status. IsOnline is updated in the CheckStatus method, and is set to True when the current IP address is not empty ('') or the default local host value

That will tell you if you are connected to your DHCP or have a fixed IP address working, but maybe that will not be enough for you, and you will want to know if you can actually access Internet. That is a start, then you should try other components :

TIdEcho (Ping) with is probably the quickest way to check "internet" availability
LVL 16

Assisted Solution

CodedK earned 125 total points
ID: 33557059
Hi rfwoolf,

Because of the variety of ways of connecting to the internet and the platform variety you want it to work
there is no real way to check.

So ping Google:

LVL 25

Assisted Solution

epasquier earned 150 total points
ID: 33557189
my bad, actually Ping is not performed with TIdEcho but with TIdIcmpClient

function CheckInternet:Boolean;
 With TIdIPWatch.Create(nil) do
   if ForceCheck Then
     with TIdIcmpClient.Create(nil) do
       Host := '';
       ReceiveTimeout:=999; //TimeOut du ping
       Result := True;
     if Not Result Then ShowMessage('Google not available !');
    end Else ShowMessage('No IP address');

Open in new window

LVL 14

Expert Comment

ID: 33557215
CodedK has the best answer.
But how long would you closed all your open post?
I have seen several question answered from delphi experts.
I'm sorry if I offended you,  but,  that is not good,  throwing some points to the experts who participated in your post is one great help.
LVL 12

Accepted Solution

Hypo earned 125 total points
ID: 33557638
There is actually a win-api function to check for internet connection called "InternetCheckConnection".
It is located in the wininet unit.

According to the help it supports the following OS: Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, or Windows 95.

uses ..., wininet;


procedure TForm3.Button1Click(Sender: TObject);
  if InternetCheckConnection('', FLAG_ICC_FORCE_CONNECTION, 0)
    then ShowMessage('Connected')
    else ShowMessage('Not connected');

Open in new window

LVL 25

Expert Comment

ID: 33559635
Yes of course ! InternetCheckConnection ! I forgot about that one...

Thanks Hypo ! And it's good to hear from you again !
LVL 14

Expert Comment

ID: 33559787
Welcome back Hypo;
I'm glad to hear you.

Before I post my first comment,  I'm thinking to post "InternetCheckConnection" but probably ping is the best and quickiest way to find out, because you can customized the byte to send, you can send 1 byte n reply.
LVL 12

Expert Comment

ID: 33566678
Thanks :) It's good to be back again... I've been way too busy with other projects for quite some time now, but I'll try to look in here more often :D


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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