|
|
导航: |
论坛 -> DELPHI技术
斑竹:liumazi,sephil |
|
作者: |
|
2004/2/21 21:51:28 |
标题: |
|
加入我的收藏 |
楼主: |
我想在程序里实现:对一个IP地址,每隔一定时间ping一次,如果结果是Request timed out,即没有数据包返回,就调用一个文件。这段程序不复杂,就是在一个循环中嵌一个if判断。判断的条件我估计可以是ping返回的某个变量,但我不知道怎么描述。 有哪位能帮助我 谢谢
----------------------------------------------
- |
作者: |
sephil (NAILY Soft) |
★☆☆☆☆ |
-
|
盒子中级会员 |
|
2004/2/21 23:28:12 |
1楼: |
function Ping(const IP: String): Integer; begin // Ping的实现我不写了 // 网上有很多例子,一般这个函数返回的都是收到的数据包大小 // 0就是ping不通咯 end;
var DoLoop: Boolean = True;
// 执行循环操作 procedure StartPing; begin DoLoop := True;
repeat // Ping不通 if Ping <= 0 then 执行操作; Application.ProcessMessages; until not DoLoop; end;
// 停止Ping循环 procedure StopPing; begin DoLoop := False; end;
以后执行 StartPing 开始循环 执行 StopPing 中断循环
----------------------------------------------
Copyright 2008 ? NAILY Soft Click here to redirect to my home Click here to redirect to my blog
|
作者: |
|
2004/2/22 10:06:31 |
2楼: |
这里面我用了个ICMP控件,在indy Clients里面 我是用这个控制重启动机器的,我的button1 click连接到重起机器的 一段程序,这里就不贴出来了,你要用的就这些了,好象应该注意ICMPReply属性
procedure TForm1.btnpingClick(Sender: TObject); var i : integer; begin ICMP.OnReply := ICMPReply; Icmp.ReceiveTimeout := 1000; btnping.Enabled := false; try ICMP.Host := edit1.text; for i := 1 to 4 do begin ICMP.Ping; Application.ProcessMessages; end; finally btnping.Enabled:= true; end; end; procedure TForm1.ICMPReply(ASender: TComponent; const AReplyStatus: TReplyStatus); //双击Reply属性 var sTime : integer; begin stime := areplystatus.TimeToLive; if stime = 0 then //网络不通 button1.Click; //此处接其他程序 end;
----------------------------------------------
|
|