if (@ICMPCreateFile = Nil) or (@IcmpCloseHandle = Nil) or (@IcmpSendEcho=Nil) then begin
ShowMessage(‘Error loading dll functions’);
halt;
end;
hICMP ∶= IcmpCreateFile;
if hICMP=INVALID_HANDLE_VALUE then
begin
ShowMessage(‘Unable to get ping handle’);
halt;
end;
end;
else begin
ShowMessage(‘Unable to register’+ icmpDLL);
halt;
end;
end;
複製代碼
2. 使用定时器启动探测
在测试中,如果端口状态正常,则net_stat=0;状态异常则net_stat=1,并显示“中断”,系统响铃报警。对节点表中所有节点进行测试的主要代码如下:
//取得欲测试端口的IP地址
net_ip∶=Table1. FieldByName(‘对端IP’). asstring;
//调用端口测试
Test(Sender);
if net_stat=0 then
begin
Table1. FieldByName(‘状态’). asstring∶=‘中断’;
//端口异常,则net=1
if net=0 then net∶=1;
end else
Table1. FieldByName(‘状态’). asstring∶=‘正常’;
//整表测试后,如有异常的端口,则10次响铃报警
if net = 1 then
FOR I := 1 TO 10 DO PlaySound(‘RINGIN’, 0, SND_RESOURCE);