掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
スレッドを使用してPINGを飛ばすには? (ID:8748)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
こんにちわです。 Indyは少し興味があったのでちょびっとだけテストしてみました。 実際の運用の際はスレッド内を適当にsyncronizeしてあげてください。 テストする際下手な値を入れるとネットワーク管理者に怒られますぞ。 >//------------------------------------------------------------------------- >//メインフォーム Unit1.pas >//------------------------------------------------------------------------- uses に PingThreadを追加 Button1,Edit1,ListBox1 procedure TForm1.Button1Click(Sender: TObject); var pthread:array [0..255] of TPingThread; i:integer; bufstr:string; begin for i:=0 to 20 do //多すぎるとOS止まります begin pthread[i]:=TPingThread.Create(True); pthread[i].IdIcmpClient1:=TIdIcmpClient.Create(self); bufstr:=Edit1.Text + inttostr(i); //Edit1.text:='***.***.***.' pthread[i].IdIcmpClient1.Host:=bufstr; pthread[i].Resume; end; >//------------------------------------------------------------------------- >//スレッド PingThread.pas >//------------------------------------------------------------------------- unit PingThread; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient; type TPingThread = class(TThread) private { Private 宣言 } procedure IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); public IdIcmpClient1: TIdIcmpClient; protected procedure Execute; override; end; implementation uses Unit1; { TPingThread } procedure TPingThread.Execute; begin IdIcmpClient1.OnReply:=IdIcmpClient1Reply; IdIcmpClient1.Ping; end; procedure TPingThread.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); begin //本当はマズイ Form1.ListBox1.Items.Add(AReplyStatus.FromIpAddress); IdIcmpClient1.Free; end; end. >//-------------------------------------------------------------------------
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.