首页 > Windows开发 > 详细

Delphi Ping检测联网状态

时间:2014-11-01 20:23:37      阅读:473      评论:0      收藏:0      [点我收藏+]

Delphi Ping检测联网状态

uses IdBaseComponent, IdComponent, IdRawBase,  IdRawClient, IdIcmpClient;

function PingServer(HostIP: string;LinkTimeOut: integer): boolean;
var
  RRemoteC: TIdIcmpClient;
  AReplyStatus: TReplyStatus;
begin
  try
    result := true;
    RRemoteC := TIdIcmpClient.Create(nil);
    RRemoteC.Host := HostIP;
    RRemoteC.ReceiveTimeout := LinkTimeOut;
    try
      RRemoteC.Ping;
      AReplyStatus := RRemoteC.ReplyStatus;
      if (AReplyStatus.ReplyStatusType = rsTimeOut) then
      begin
        result := false;
      end;
    except
      result := false;
    end;
  finally
    RRemoteC.Free;
  end;
end;

调用:

if PingServer(‘www.baidu.com‘, 5000) then xxx

Delphi Ping检测联网状态

原文:http://www.cnblogs.com/huavsheng/p/4067648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!