Internet Connection...

Is there an easy way to see if a computer is connected to the internet? It needs to work on both modem-and Lan connections.

Regards
Retep
retepAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
Listening
0
intheCommented:
Hi,

here is a way that may help:


uses wininet;

function IsConnectedToInternet : bool;
begin
dwConnectionTypes := INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN
+ INTERNET_CONNECTION_PROXY;

if InternetGetConnectedState(@dwConnectionTypes, 0) then
Result := True
else
Result := False;
end;


if that fails to work you can use the component here as it seems t work quite well:

http://members.xoom.com/kirez/download.htm 

Regards Barry
0
retepAuthor Commented:
Delphi doesn't know 'dwConnectionTypes' and 'InternetGetConnectedState'... ?

Before I look into a component, I'll just wait and see if someone posts an easy function :-)

Regards
Retep
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

intheCommented:
Hi,
sorry i never typed that properly please try again,the InternetGetConnectedState function checks Lan,Modem,and proxy to see if your connected or not.

//note i added Wininet to the uses section.

procedure TForm1.Button1Click(Sender: TObject);
var  
 dwConnectionTypes: dWord;
begin
 dwConnectionTypes := 0;
if InternetGetConnectedState(@dwConnectionTypes, 0) then
  showmessage('connected')
 else
  showmessage('not connected');
end;

Regards Barry
0
ckanetaCommented:
I do it the hard way, myself. the way
described before seems much simpler, but
if it doesn't work this is what I do.
first have it check the local IP.  if
it is not null or 127.0.0.1, then I
try to ping three different sites
yahoo, altavista, and microsoft and if
it times out on each of those three, I
pretty much assume you aren't connected.

0
retepAuthor Commented:
Hi Inthe ;-)

I'm sorry to say this, but it still doesn't work. I'm connected to the internet with cable-modem, and nomatter what, it tells me that I'm connected... :-/

Regards
Retep
0
bryan7Commented:
listenning
0
ckanetaCommented:
okay this is the way I did it, kind of
lengthy and involved, but it works(even on a LAN)
first, I use a component I downloaded from Torry's delphi pages (all it really does is check the local IP and compare it to nil and 127.0.0.1)
if that says disconnected you use a dial-up connection, and are not connected, otherwise you are on a LAN or some such and may or may not be connected.  At this point I try to connect with an echo component---

try echo.connect;
 except on ESockError do begin
  showmessage('Not Connected');
  ival:=0;
 end;

I put in a timer because it had a tendancy to halt the program if you weren't connected(the interval for the timer is set to 1 sec)

procedure Tmnfrm.tmrTimer(Sender: TObject);
 begin
  ival:=ival+1; if ival=2 then  
   tmr.enabled:=false;
 end;

so, after all this if ival is not 0 then it means you were connected as the echo component did not time out, so you can go ahead and do all that you need to do
0
intheCommented:
did you try the component i pointed to ?
0
retepAuthor Commented:
ckaneta>> As I told InThe, I'm trying to avoid a component...

But if you could tell me how you ping a server from one of Delphi's (nr. 4) own components I would be very happy...

Regards
Peter
0
intheCommented:
sorry i hate to say it but i use TPing from F.piettes site:
it comes with example that shows how to use it .
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
retepAuthor Commented:
He he, okay it seems that I'll have to look into some component stuff anyway... :-)

Thanks to all of you, I have accepted Inthe's answer... If anyone feels that they are entiteled to some points (which would be fair) then please let me know, and I'll post some questions in their names...

Regards
Retep

0
intheCommented:
can i have some ?

heh just kidding ,sorry to have to use component after all ;-]
0
retepAuthor Commented:
I have an idea that I'll have to get used to using all sorts of components. So I might as well get started ;-)
0
intheCommented:
hehe
you should see my component pallet,i have 47 tabs and every one is full + some are overflowing ..but i say why re-invent the wheel and all that ;-)

see you again .
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.