Delphi Ping检测联网状态

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检测联网状态

上一篇:apache在windows下的命令安装与报错解决


下一篇:Delphi系统托盘组件 TTrayIcon 简介