如何寫出一個最簡單的 ping
用 Indy 可以很快的寫一個簡單的 ping 程式,適合 Delphi 7 開發,在 XP 執行。
注意:執行程式的使用者需具有系統管理員權限
在 Form 上放 1 個 TidIcmpClient, 1 個 TEdit 和 1 個 Button
Button1.OnClick 程式碼:
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ICMP.Host := Edit1.Text;
ICMP.Ping;
finally
end;
end;
IdIcmpClient1.OnReply 程式碼:
procedure TForm1.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
begin
if AReplyStatus.BytesReceived=0 then
showmessage('time out') // PING 不到
else
showmessage(inttostr(AReplyStatus.BytesReceived)+ ' mSec'); // 顯示 PING 的時間
end;
相關筆記 ----
【Delphi】以 icmp.dll 去 ping 網路設備
【Delphi】以 WMI 方式 ping 網路設備
沒有留言:
張貼留言