Delphi检查网络

2025-03-25 21:11:08
推荐回答(2个)
回答1:

use IdBaseComponent, IdComponent, IdRawBase, IdRawClient,IdIcmpClient
用下面的函数就可以判断了
function TFrmMain.Ping(const url: string): Boolean;
var
aIdICMPClient: TIdICMPClient;
begin
if Trim(url) = '' then
begin
Result := False;
Exit;
end;
aIdICMPClient := TIdICMPClient.Create(nil);
aIdIcmpclient.ReceiveTimeout := 1000; //1500ms is timeout
aIdICMPClient.Host := url;
try
aIdICMPClient.Ping();
except
Result := False;
end;
if (aidicmpclient.ReplyStatus.fromipaddress <> '0.0.0.0 ')
and (aidicmpclient.ReplyStatus.fromipaddress <> '') and (aidicmpclient.ReplyStatus.BytesReceived > 0) then
Result := True
else
Result := False;
aIdICMPClient.Free;
end;

回答2:

是不是检查网络通或不通呢?
集成的indy控件就可以实现要求了。