フォーラム


ゲスト  

ようこそ ゲスト さん。このフォーラムに投稿するには 登録が必要です。

ページ: [1]
トピック: Indy で Ping を打つ
DEKO
管理者
投稿数: 2690
Indy で Ping を打つ
on: 2013/04/18 12:47 Thu

Ping は Indy の TIdIcmpClient で実現できます。
以下に単純な Ping の関数を記述しておきます。

uses
..., IdIcmpClient, IdStack;

interface

...
function SimplePing(AHost: string; ATimeout: Integer = 3000): Boolean;

implementation

...

function SimplePing(AHost: string; ATimeout: Integer): Boolean;
var
IcmpClient: TIdIcmpClient;
begin
result := False;
IcmpClient := TIdIcmpClient.Create;
try
with IcmpClient do
begin
Host := AHost;
PacketSize := 32;
ReceiveTimeout := ATimeout;
try
Ping;
result := True;
except
on E: EIdSocketError do
result := False;
end;
end;
finally
IcmpClient.Free;
end;
end;

 
※ NT4.0~XP でこのコードを実行するにはユーザが管理者である必要があります。Vista 以降でこのコードを実行するには管理者への昇格が必要です。

See Also:
[Indy IDIcmpClient Ping Problem]
http://embarcadero.newsgroups.archived.at/public.delphi.internet.winsock/200812/081213765.html

ページ: [1]
WP Forum Server by ForumPress | LucidCrew
バージョン: 1.7.5 ; ページロード: 0.025 sec.