全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:6046
推到 Plurk!
推到 Facebook!

關於delphi的ping

答題得分者是:geniustom
breeze_1
一般會員


發表:33
回覆:72
積分:21
註冊:2003-05-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-22 18:18:04 IP:202.104.xxx.xxx 未訂閱
編一delphi程式,ping 一系列的ip地址,接受其返回信息,記錄其ping的時間和 返回的時間,並確定是否ping得通.記錄在ini文件中. 當然不一定要用PING,只要 能確定是否能連上那個IP即可. 拜托各位賜教!
hjhjack1
一般會員


發表:7
回覆:32
積分:24
註冊:2002-08-07

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-27 12:45:50 IP:202.173.xxx.xxx 未訂閱
DEKPHI 6.0以上INDY範例就有,ROUTER PING都有
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-27 15:37:58 IP:61.155.xxx.xxx 未訂閱
用delphi实现ping  及原码 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=36409
geniustom
版主


發表:100
回覆:303
積分:260
註冊:2003-01-03

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-08-28 07:56:17 IP:219.68.xxx.xxx 未訂閱
使用INDY CLIENTS頁籤裡的IdIcmpClient..PING判定為TIMEOUT的時間可由ReceiveTimeout這個屬性來設定..以下是範例(我試過可用)請注意紅色部分 -----------------------------------------------------------------
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdRawBase, IdRawClient,
  IdIcmpClient;    type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    IdIcmpClient1: TIdIcmpClient;
    procedure Button1Click(Sender: TObject);
    procedure IdIcmpClient1Reply(ASender: TComponent;
      const AReplyStatus: TReplyStatus);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject);
begin
   IdIcmpClient1.Host:=edit1.Text;
   IdIcmpClient1.Ping;
end;    procedure TForm1.IdIcmpClient1Reply(ASender: TComponent;
  const AReplyStatus: TReplyStatus);
begin
   if AReplyStatus.BytesReceived=0 then 
      showmessage('time out')  //PING不到
   else
   showmessage(inttostr(AReplyStatus.BytesReceived) ' mSec'); //顯示PINGTIME
end;    end.
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2006-12-06 14:52:35 IP:219.87.xxx.xxx 未訂閱
好奇怪 procedure TForm1.IdIcmpClient1Reply 沒有執行
沒有跳出任何對話盒
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
kevinhom
一般會員


發表:0
回覆:1
積分:0
註冊:2007-01-02

發送簡訊給我
#6 引用回覆 回覆 發表時間:2007-01-02 17:46:55 IP:61.56.xxx.xxx 未訂閱
這個是我自己上班之餘無聊寫的...除了ping之外還有索取系統時間的小範例...不嫌它爛就參考看看吧...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, IdBaseComponent, IdComponent, IdRawBase,
IdRawClient, IdIcmpClient, IdTCPConnection, IdTCPClient, IdTime,
IdTCPServer, IdTimeServer;
type
TForm1 = class(TForm)
LIST: TMemo;
Panel1: TPanel;
BTN1: TButton;
ICMP: TIdIcmpClient;
BTN_STOP: TButton;
Panel2: TPanel;
Label1: TLabel;
Panel3: TPanel;
Label2: TLabel;
Label3: TLabel;
IdTime1: TIdTime;
Panel4: TPanel;
Edit1: TEdit;
Timer1: TTimer;
IdTimeServer1: TIdTimeServer;
ComboBox1: TComboBox;
procedure BTN1Click(Sender: TObject);
procedure BTN_STOPClick(Sender: TObject);
procedure ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
GO : Boolean;
implementation
{$R *.dfm}
procedure TForm1.BTN1Click(Sender: TObject);
var
I : Integer;
begin
ComboBox1.Items.Add(ComboBox1.Text);//將自行輸入的位址加到comboBox中
Go := true;
List.Clear; //每次執行程式時先將ListBox清空一次
ICMP.OnReply := ICMPReply;
ICMP.ReceiveTimeout := 1000;
BTN1.Enabled := false;
Label1.Caption := '正在進行連線Ping中.....';
Label3.Caption := '目前連結的位址是' ComboBox1.Text;
try
for I := 1 to 10000 do //ping一萬次
begin
ICMP.Host := ComboBox1.Text; //將要ping的位址送給IdIcmpClient
ICMP.Ping; //呼叫IdIcmpClient的ping函式
Application.ProcessMessages;
if Go <> TRUE then Break; //假如Go變成false就離開迴圈
SLEEP(500);//睡覺函式
end;
finally
BTN1.Enabled := true;
end;
end;
procedure TForm1.BTN_STOPClick(Sender: TObject);
begin
GO := false; //按下Stop按鈕時將Go變成false才能讓ping的函式結束
Label1.Caption := '連線已停止.....';
Label3.Caption := '目前對任何位址已無任何連結';
end;
procedure TForm1.ICMPReply(ASender: TComponent;
const AReplyStatus: TReplyStatus);
var
s : string;
begin
if (AReplyStatus.MsRoundTripTime = 0)then
begin
s := '<1';
end else
begin
S := '=';
end;
if (AReplyStatus.BytesReceived = 0)then
begin
List.Lines.Add('連結' ComboBox1.Text '失敗')
end else
begin
List.Lines.Add(Format('%d位元,從IP:%s,流水號=%d ttl=%d 回應時間 %s%d ms',
[AReplyStatus.BytesReceived,AReplyStatus.FromIpAddress,
AReplyStatus.SequenceId,
AReplyStatus.TimeToLive,s,AReplyStatus.MsRoundTripTime]));
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption := '目前尚未進行連線Ping中.....';
Label3.Caption := '歡迎使用位址連結Ping程式'
end;
procedure TForm1.Timer1Timer(Sender: TObject); //跟onTimer一樣的函式
begin
IdTimeServer1.Active := true; //自行建立的一個TimeServer變成true才能讓IDTimerCline接受的到系統時間
IdTime1.Host := '127.0.0.1'; //ping自己的IdTimerServer
EDIT1.Text := '系統時間:' DateTimeToStr(IdTime1.DateTime);
end;
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then //Key = 13 的意思跟C 中的VK_Enter一樣
begin
ComboBox1.Items.Add(ComboBox1.Text); //將自行輸入的位址加到comboBox中
BTN1.Click;//假如在comboBox按下了Enter鍵則就BTN1的按鍵按下
end;
end;
end.
joana
一般會員


發表:35
回覆:70
積分:21
註冊:2005-09-02

發送簡訊給我
#7 引用回覆 回覆 發表時間:2009-12-09 15:54:37 IP:122.116.xxx.xxx 訂閱
請教各為大德
TidcmpClient 這個元件, ping 成功後 是否要下 ICMP.FreeInstance or ICMP.Free, 免得耗用系統資源
謝謝 !
系統時間:2024-04-26 12:20:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!