1、引用以下几个单元
IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient;
2、函数模块
-------------------------------------------------------------------------------------
功能: 检查网络是否正常连通
参数: 无
返回值: 成功: True 失败: False
2014年3月22日 编写
-------------------------------------------------------------------------------------
function CheckOnLine: Boolean;
const
Url = 'www.sina.com'; //广东电信测速 0.08s
var
aIdICMPClient: TIdICMPClient;
begin
Result := False;
aIdICMPClient := TIdIcmpClient.Create(nil);
try
aIdICMPClient.ReceiveTimeout := 1000; //1500ms is timeout
aIdICMPClient.Host := Url;
try
aIdICMPClient.Ping();
if (aIdICMPClient.ReplyStatus.FromIpAddress <> '0.0.0.0') and
(aIdICMPClient.ReplyStatus.FromIpAddress <> '') and
(aIdICMPClient.ReplyStatus.BytesReceived > 0) then //有收到数据
Result := True;
except
Result := False;
end;
finally
aIdICMPClient.Free;
end;
end;