zoukankan      html  css  js  c++  java
  • delphi 测试ping

    type
      TForm1 = class(TForm)
        idcmpclnt1: TIdIcmpClient;
        cxbtn1: TcxButton;
        cxbtn2: TcxButton;
        pnl1: TPanel;
        edtHost: TcxTextEdit;
        cxm1: TcxMemo;
        cxText_count: TcxTextEdit;
        procedure cxbtn1Click(Sender: TObject);
        procedure cxbtn2Click(Sender: TObject);
        procedure idcmpclnt1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
      private
        { Private declarations }
        b, i, s: Integer;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.cxbtn1Click(Sender: TObject); //执行Ping操作
    begin
      b := 0; //掉包数量
      i := 0; //Ping的总次数
      s := 0; //执行(s=0)或停止(s=1)标志
      cxm1.Clear; //清除上次Ping的信息
    
      idcmpclnt1.Host := edtHost.Text;   //设置IP
      while (i < 100000) and (s = 0) do
      begin //最多执行10万次Ping操作
        Application.ProcessMessages;
        i := i + 1;
        idcmpclnt1.Ping; //执行Ping
       //若前10次Ping都失败则结束Ping
    
        if (i = 10) and (b = 10) then
          s := 1;
      end;
    end;
    
    procedure TForm1.cxbtn2Click(Sender: TObject); //停止Ping操作
    begin
      s := 1; //置Ping操作停止标志
    end;
    
    procedure TForm1.idcmpclnt1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
    var
      Msg: string;
      Tm: integer;
    begin
      with AReplyStatus do
      begin
        Msg := 'Reply from ' + edtHost.Text;
        Msg := Msg + ' bytes=' + IntToStr(BytesReceived); //返回字节数
        Msg := Msg + ' TTL=' + IntToStr(TimeToLive); //返回生存时间
        Tm := MsRoundTripTime; //返回执行时间
    
        if Tm < 1 then
          Tm := 1;
        Msg := Msg + ' time=' + IntToStr(Tm) + 'ms';
        cxm1.Lines.Add(Msg); //保存信息
    
        if (BytesReceived = 0) or (TimeToLive = 0) then
        begin //无数据返回
          b := b + 1; //记录掉包数量
          cxText_count.text := IntToStr(b); //记录掉包数
        end;
    
        if i mod 100 = 0 then  //每Ping到100次显示一次掉包情况
          pnl1.Caption := 'Lost:' + IntToStr(b) + '/' + IntToStr(i) + '=' + copy(FloatToStr(b / i * 1000), 1, 4) + '';
    
      end;
    end;
  • 相关阅读:
    【XXE学习】XML外部实体注入
    记一次解密wireshark抓取的冰蝎通信流量
    weblogicSSRF漏洞复现
    解决docker删除加载失败的镜像报错
    【vulapps】Sturcts2 S2-037RCE漏洞复现
    【XSS-labs】level 16-20
    解决docker-compose下载过慢
    【XSS-labs】Level 11-15
    【XSS-labs】level 6-10
    [PHP]用PHP自己写一个基于zoomeye的api(偷懒必备quq)
  • 原文地址:https://www.cnblogs.com/yangxuming/p/8520696.html
Copyright © 2011-2022 走看看