Ping イベント
パブリック イベント
名前 | 説明 | |
---|---|---|
Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。 ( Component から継承されます。) | |
PingCompleted | 非同期の操作が ICMP (インターネット コントロール メッセージ プロトコル) エコー メッセージを送信し、対応する ICMP エコー応答メッセージの受信を完了するか、またはキャンセルされたときに発生します。 |
Ping クラス
アセンブリ: System (system.dll 内)
構文
Public Class Ping Inherits Component Implements IDisposable
public class Ping : Component, IDisposable
public class Ping extends Component implements IDisposable
public class Ping extends Component implements IDisposable
アプリケーションは、Ping クラスを使用して、リモート コンピュータが到達可能かどうかを検出します。
Ping が正常にリモート ホストと通信できるかどうかは、ネットワーク トポロジで決まる可能性があります。プロキシ、NAT (Network Address Translation) 設備、またはファイアウォールの存在および設定によっては、Ping が正常に動作しない可能性があります。Ping が成功しても、ネットワークを経由してリモート ホストに到達できることが示されただけです。より高レベルなサービス (Web サーバーなど) がリモート ホストに存在するかどうかは保証されません。
このクラスは、Ping.exe コマンド ライン ツールと同様の機能を提供します。Send メソッドおよび SendAsync メソッドは、ICMP (インターネット コントロール メッセージ プロトコル) エコー要求メッセージをリモート コンピュータに送信し、そのコンピュータからの ICMP エコー応答メッセージを待機します。ICMP メッセージの詳細については、http://www.ietf.org から RFC 792 を参照してください。
IPStatus | |
PingOptions | 要求パケットを転送できる回数 (Ttl)、および断片化できるかどうか (DontFragment) を制御する設定を構成および取得できるようにします。 |
PingReply | |
PingException | |
PingCompletedEventArgs | PingCompleted イベントに関連付けられたデータを格納します。このイベントは、SendAsync の呼び出しが完了またはキャンセルされたときに発生します。 |
PingCompletedEventHandler | SendAsync の呼び出しが完了またはキャンセルされたときに呼び出されるコールバック メソッドを提供するデリゲートです。 |
Send メソッドおよび SendAsync メソッドは、PingReply オブジェクトに応答を返します。PingReply.Status プロパティは、要求の結果を示す IPStatus 値を返します。
要求を送信するときには、リモート コンピュータを指定する必要があります。この指定には、ホスト名文字列、文字列形式の IP アドレス、または IPAddress オブジェクトを使用できます。
-
要求に付随するデータ。buffer を指定することにより、特定のサイズのパケットがリモート ホストとの間を往復するために必要な合計時間、およびそのネットワーク パスの MTU (Maximum Transmission Unit) を確認できます。(buffer パラメータを受け取る、Send や SendAsync のオーバーロードを参照してください。)
-
ICMP の エコー パケットを送信中に断片化できるかどうか。(DontFragment プロパティ、および options パラメータを受け取る Send や SendAsync のオーバーロードを参照してください。)
-
パケットが送信先のコンピュータに到達するか破棄される前に、ルーターやゲートウェイなどのルーティング ノードがパケットを転送できる回数。(Ttl、および options パラメータを受け取る Send や SendAsync のオーバーロードを参照してください。)
-
応答が受信される必要のある制限時間。(timeout パラメータを受け取る Send や SendAsync のオーバーロードを参照してください。)
Ping クラスは、要求を送信するための同期メソッドと非同期メソッドの両方を提供します。応答を待つ間にアプリケーションをブロックさせる場合は、Send メソッドを使用します。これらは同期メソッドです。アプリケーションをブロックさせない場合は、非同期の SendAsync メソッドを使用します。SendAsync を呼び出すと、スレッド プールから自動的に割り当てられる独自のスレッドで実行されます。非同期操作が完了すると、PingCompleted イベントが発生します。アプリケーションは、PingCompletedEventHandler デリゲートを使用して、PingCompleted イベントで呼び出されるメソッドを指定します。SendAsync を呼び出す前に、PingCompletedEventHandler デリゲートをイベントに追加する必要があります。デリゲートのメソッドは、SendAsync 呼び出しの結果を表す PingReply オブジェクトが格納された PingCompletedEventArgs オブジェクトを受け取ります。
Ping クラスの同じインスタンスを使用して、複数の ICMP エコー要求を同時に生成することはできません。SendAsync の呼び出し中に Send を呼び出したり、SendAsync を前回の呼び出しがすべて完了する前に複数回呼び出したりすると、InvalidOperationException が発生します。
using System; using System.Net; using System.Net.NetworkInformation; using System.Text; namespace Examples.System.Net.NetworkInformation.PingTest { public class PingExample { // args[0] can be an IPaddress or host name. public static void Main (string[] args) { Ping pingSender = new Ping (); PingOptions options = new PingOptions (); // Use the default Ttl value which is 128, // but change the fragmentation behavior. options.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes (data); int timeout = 120; PingReply reply = pingSender.Send (args[0], timeout, buffer, options); if (reply.Status == IPStatus.Success) { Console.WriteLine ("Address: {0}", reply.Address.ToString ()); Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine ("Time to live: {0}", reply.Options.Ttl); Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length); } } } }
Ping クラスを非同期的に使用するコード例を次に示します。
using System; using System.Text; using System.Net; using System.Net.NetworkInformation; using System.ComponentModel; using System.Threading; namespace Examples.System.Net.NetworkInformation.PingTest { public class PingExample { public static void Main (string[] args) { if (args.Length == 0) throw new ArgumentException ("Ping needs a host or IP Address."); string who = args[0]; AutoResetEvent waiter = new AutoResetEvent (false); Ping pingSender = new Ping (); // When the PingCompleted event is raised, // the PingCompletedCallback method is called. pingSender.PingCompleted += new PingCompletedEventHandler (PingCompletedCallback); // Create a buffer of 32 bytes of data to be transmitted. string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; byte[] buffer = Encoding.ASCII.GetBytes (data); // Wait 12 seconds for a reply. int timeout = 12000; // Set options for transmission: // The data can go through 64 gateways or routers // before it is destroyed, and the data packet // cannot be fragmented. PingOptions options = new PingOptions (64, true); Console.WriteLine ("Time to live: {0}", options.Ttl); Console.WriteLine ("Don't fragment: {0}", options.DontFragment); // Send the ping asynchronously. // Use the waiter as the user token. // When the callback completes, it can wake up this thread. pingSender.SendAsync(who, timeout, buffer, options, waiter); // Prevent this example application from ending. // A real application should do something useful // when possible. waiter.WaitOne (); Console.WriteLine ("Ping example completed."); } public static void PingCompletedCallback (object sender, PingCompletedEventArgs e) { // If the operation was canceled, display a message to the user. if (e.Cancelled) { Console.WriteLine ("Ping canceled."); // Let the main thread resume. // UserToken is the AutoResetEvent object that the main thread // is waiting for. ((AutoResetEvent)e.UserState).Set (); } // If an error occurred, display the exception to the user. if (e.Error != null) { Console.WriteLine ("Ping failed:"); Console.WriteLine (e.Error.ToString ()); // Let the main thread resume. ((AutoResetEvent)e.UserState).Set(); } PingReply reply = e.Reply; DisplayReply (reply); // Let the main thread resume. ((AutoResetEvent)e.UserState).Set(); } public static void DisplayReply (PingReply reply) { if (reply == null) return; Console.WriteLine ("ping status: {0}", reply.Status); if (reply.Status == IPStatus.Success) { Console.WriteLine ("Address: {0}", reply.Address.ToString ()); Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine ("Time to live: {0}", reply.Options.Ttl); Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment); Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length); } } } }
System.MarshalByRefObject
System.ComponentModel.Component
System.Net.NetworkInformation.Ping
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Ping コンストラクタ
アセンブリ: System (system.dll 内)
構文
使用例
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Ping プロパティ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Container | Component を格納している IContainer を取得します。 ( Component から継承されます。) | |
Site | Component の ISite を取得または設定します。 ( Component から継承されます。) |
名前 | 説明 | |
---|---|---|
CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。 ( Component から継承されます。) | |
DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。 ( Component から継承されます。) | |
Events | Component に結び付けられているイベント ハンドラのリストを取得します。 ( Component から継承されます。) |
Ping メソッド
パブリック メソッド
名前 | 説明 | |
---|---|---|
Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 ( Component から継承されます。) | |
Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 ( Component から継承されます。) | |
GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 ( Component から継承されます。) | |
MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) | |
OnPingCompleted | PingCompleted イベントを発生させます。 |
参照
Ping メンバ
リモート コンピュータにネットワーク経由でアクセスできるかどうかをアプリケーションで確認できるようにします。
パブリック コンストラクタ
パブリック プロパティ
名前 | 説明 | |
---|---|---|
Container | Component を格納している IContainer を取得します。(Component から継承されます。) | |
Site | Component の ISite を取得または設定します。(Component から継承されます。) |
名前 | 説明 | |
---|---|---|
CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。(Component から継承されます。) | |
DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。(Component から継承されます。) | |
Events | Component に結び付けられているイベント ハンドラのリストを取得します。(Component から継承されます。) |
名前 | 説明 | |
---|---|---|
Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 (Component から継承されます。) | |
Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 (Component から継承されます。) | |
GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 (Component から継承されます。) | |
MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) | |
OnPingCompleted | PingCompleted イベントを発生させます。 |
名前 | 説明 | |
---|---|---|
Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。(Component から継承されます。) | |
PingCompleted | 非同期の操作が ICMP (インターネット コントロール メッセージ プロトコル) エコー メッセージを送信し、対応する ICMP エコー応答メッセージの受信を完了するか、またはキャンセルされたときに発生します。 |
参照
固有名詞の分類
Weblioに収録されているすべての辞書からPingを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からPingを検索
- Pingのページへのリンク