高分求助
试写一个监听ping 命令的程序,不管不什么语言都可以,最好是把代码奉献一写。十分感谢。
[解决办法]
参看:
unit ping;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdRawBase,
IdRawClient, IdIcmpClient;
type
TPingFrm = class(TForm)
ICMP: TIdIcmpClient;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
ListBox1: TListBox;
procedure Button2Click(Sender: TObject);
procedure ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
PingFrm: TPingFrm;
implementation
{$R *.dfm}
procedure TPingFrm.Button2Click(Sender: TObject);
begin
ListBox1.Clear ;
end;
procedure TPingFrm.ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
var
sTime: string;
begin
if AReplyStatus.ReplyStatusType=rsError then showmessage( 'hello* ');
if (AReplyStatus.MsRoundTripTime = 0 ) then
sTime := ' <1 '
else
sTime := '= ';
ListBox1.Items.Add(Format( 'ICMP_SEQ=%d Reply from %s [%s] : Bytes=%d time%s%d ms TTL=%d ',
[AReplyStatus.SequenceId,
Edit1.Text,
AReplyStatus.FromIpAddress,
AReplyStatus.BytesReceived,
sTime,
AReplyStatus.MsRoundTripTime,
AReplyStatus.TimeToLive]));
end;
procedure TPingFrm.Button1Click(Sender: TObject);
var
i : integer;
begin
ICMP.Host := Edit1.Text ;
ICMP.ReceiveTimeout := 1000;
Button1.Enabled := false;
try
for i:=0 to 3 do
begin
ICMP.Ping ;
Application.ProcessMessages ;
end;
except
on e:exception do showmessage( 'hlo* ') ;
end;
finally
Button1.Enabled := true;
end;
end;
end.