Delphi Ping

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;

  

posted @ 2020-05-10 11:58  @王新@  阅读(184)  评论(0编辑  收藏  举报