2016-12-12

【Delphi】以 Indy TIdIcmpClient 去 ping 網路設備

參考資料 ----
如何寫出一個最簡單的 ping


Indy 可以很快的寫一個簡單的 ping 程式,適合 Delphi 7 開發,在 XP 執行。

注意:執行程式的使用者需具有系統管理員權限

Form 上放 1 個 TidIcmpClient, 1 個 TEdit 和 1 個 Button



Button1.OnClick 程式碼:
  1.  
  2. procedure TForm1.Button1Click(Sender: TObject);
  3. begin
  4. try
  5. ICMP.Host := Edit1.Text;
  6. ICMP.Ping;
  7. finally
  8.  
  9. end;
  10. end;
  11.  


IdIcmpClient1.OnReply 程式碼:
  1.  
  2. procedure TForm1.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
  3. begin
  4. if AReplyStatus.BytesReceived=0 then
  5. showmessage('time out') // PING 不到
  6. else
  7. showmessage(inttostr(AReplyStatus.BytesReceived)+ ' mSec'); // 顯示 PING 的時間
  8. end;
  9.  


相關筆記 ----
【Delphi】以 icmp.dll 去 ping 網路設備
【Delphi】以 WMI 方式 ping 網路設備

沒有留言:

張貼留言