大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> Delphi编程实现Ping操作

Delphi编程实现Ping操作

时间: 2021-07-31 作者:daque

在delphi中运用tidicmpclient控件不妨特殊大略的实行图形界面包车型的士ping!兴建一个工程,定名为pinggui.dpr,窗口定名为“frmping”,介入如次组件:    lstreplies: tlistbox;    icmp: tidicmpclient;    panel1: tpanel;    btnping: tbutton;    edthost: tedit;    spnping: tspinedit;    label1: tlabel;完备源代码如次:unit main;interface

uses  windows, messages, graphics, controls, forms, dialogs, stdctrls, extctrls,  sysutils, classes, idicmpclient, idbasecomponent, idcomponent, idrawbase, idrawclient,  spin;

type  tfrmping = class(tform)    lstreplies: tlistbox;    icmp: tidicmpclient;    panel1: tpanel;    btnping: tbutton;    edthost: tedit;    spnping: tspinedit;    label1: tlabel;    procedure btnpingclick(sender: tobject);    procedure icmpreply(asender: tcomponent; const replystatus: treplystatus);  private  public  end;

var  frmping: tfrmping;

implementation{$r *.dfm}

procedure tfrmping.btnpingclick(sender: tobject);var  i: integer;begin  icmp.onreply := icmpreply;  icmp.receivetimeout := 1000;  btnping.enabled := false; try    icmp.host := edthost.text;    for i := 1 to spnping.value do begin      icmp.ping;      application.processmessages;    end;  finally btnping.enabled := true; end;end;

procedure tfrmping.icmpreply(asender: tcomponent; const replystatus: treplystatus);var  stime: string;begin  // todo: check for error on ping reply (replystatus.msgtype?)  if (replystatus.msroundtriptime = 0) then    stime := '<1'  else    stime := '=';

  lstreplies.items.add(format('%d bytes from %s: icmp_seq=%d ttl=%d time%s%d ms',    [replystatus.bytesreceived,    replystatus.fromipaddress,    replystatus.sequenceid,    replystatus.timetolive,    stime,    replystatus.msroundtriptime]));end;

end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.