Mastodon
Programmierung

Is the Computer connected to internet?

> Can someone tell me how to find out in a application if the computer running
> it is connected to the internet. When I try a URL using DNSLookup or
> whatever the RAS-dialler is automatically started. I just want to know if
> there is a valid internet connection by lan/proxy/cable/ras or not. (Like
> delphi does with the news messages popup when you start delphi with an
> internetconnection open).
> Jef.

//You will have to include Winsock.pas

[code lang=”delphi”]Function TSysInfo.GetCurrentIpList:TSTringList;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;

begin
Result:=TStringList.Create;
WSAStartup($101, GInitData);
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result.add(StrPas(inet_ntoa(pptr^[I]^)));
Inc(I);
end;
WSACleanup;
end;
[/code]

[tags]Delphi, Internet[/tags]

0 Kommentare zu “Is the Computer connected to internet?

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.