USES
WinInet;
..
..
function InternetConnected: Boolean;
CONST
// local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = 1;
// local system uses a local area network to connect to the Internet.
INTERNET_CONNECTION_LAN = 2;
// local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = 4;
// local system's modem is busy with a non-Internet connection.
INTERNET_CONNECTION_MODEM_BUSY = 8;
VAR
dwConnectionTypes : DWORD;
BEGIN
dwConnectionTypes :=
INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
Result := InternetGetConnectedState(@dwConnectionTypes,0);
END;
Tips에 퍼왔는데요!
실행을 해 보니 항상 결과는 참인데... 이래도 되는 건가요?
네트웍선을 뽑고 실행하면 거짓값이 반환되어야 하는데,
미치겠네요!
결과는 즉시 나타나지 않습니다.
지속적으로 조사하고 있어야 겠지요.
그럼~ 항상 즐거운프로그래밍 하시길~
function IsOnline: Boolean;
var
Size: Integer;
PC: array[0..4] of Char;
Key: hKey;
function IsIPPresent: Boolean;
type
TaPInAddr = array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
IP: string;
begin
WSAStartup($101, GInitData);
Result := False;
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
IP := inet_ntoa(pptr^[I]^);
Inc(I);
end;
WSACleanup;
Result := (IP <> '') and (IP <> '127.0.0.1');
end;
begin
if RegOpenKey(HKEY_LOCAL_MACHINE, 'SystemCurrentControlSetServicesRemoteAccess', Key) = ERROR_SUCCESS then
begin
Size := 4;
if RegQueryValueEx(Key, 'Remote Connection', nil, nil, @PC, @Size) = ERROR_SUCCESS then
Result := PC[0] = #1
else
Result := IsIPPresent;
RegCloseKey(Key);
end
else
Result := IsIPPresent;
end;