利用Delphi里面的IdIcmpClient控制来检测网络是否正常连通

来源:互联网 发布:update更新多条数据 编辑:程序博客网 时间:2024/06/05 03:23

1、引用以下几个单元

     IdBaseComponent, IdComponent, IdRawBase,  IdRawClient, IdIcmpClient;

2、函数模块

-------------------------------------------------------------------------------------

        功能: 检查网络是否正常连通   

        参数: 无

        返回值: 成功: True   失败: False

       2014年3月22日  编写

-------------------------------------------------------------------------------------


function CheckOnLine: Boolean;const  Url = 'www.sina.com'; //广东电信测速 0.08svar  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;

0 0
原创粉丝点击