This example is used to detect the normal communication between the host and the Ping class. Delay how many milliseconds, etc...
The complete code is as follows:
Introduction of namespaces:
Using System.Net.NetworkInformation;
Complete code:
namespace Pingexample {public partial class Form1:form {public Form1 () {Initializ
Ecomponent (); } private void Btn_startping_click (object sender, EventArgs e) {this.lst_PingResult.Items.Cl
Ear (); Remote server IP String ipstr = txt_IPAddress.Text.ToString ().
Trim ();
Construct Ping instance Ping Pingsender = new Ping ();
Ping option to set pingoptions options = new PingOptions (); Options.
Dontfragment = true;
Test Data String = "Test Abcabc";
byte[] buffer = Encoding.ASCII.GetBytes (data);
Set timeout time int timeout = 120;
Call the synchronous send method to send the data and save the return result to the pingreply instance pingreply reply = Pingsender.send (ipstr, timeout, buffer, options); if (reply. Status = = ipstatus.success {LST_PINGRESULT.ITEMS.ADD ("host address of reply:" + reply.)
Address.tostring ()); LST_PINGRESULT.ITEMS.ADD ("Round Trip Time:" + reply.)
Roundtriptime); LST_PINGRESULT.ITEMS.ADD (Live Time (TTL): + reply.
OPTIONS.TTL); LST_PINGRESULT.ITEMS.ADD ("Control packet Fragmentation:" + reply.)
Options.dontfragment); LST_PINGRESULT.ITEMS.ADD ("Buffer size:" + reply.)
Buffer.length); else Lst_PingResult.Items.Add (reply.
Status.tostring ());
}
}
}
If the above code is not compiled, you can download the complete example to the following address:
http://download.csdn.net/source/3464606