http://blog.csdn.net/andrew_wx/article/details/6628501
using System.Net.NetworkInformation; namespace PingExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn_StartPing_Click(object sender, EventArgs e) { this.lst_PingResult.Items.Clear(); //遠程服務器IP string ipStr = txt_IPAddress.Text.ToString().Trim(); //構造Ping實例 Ping pingSender = new Ping(); //Ping 選項設置 PingOptions options = new PingOptions(); options.DontFragment = true; //測試數據 string data = "test data abcabc"; byte[] buffer = Encoding.ASCII.GetBytes(data); //設置超時時間 int timeout = 120; //調用同步 send 方法發送數據,將返回結果保存至PingReply實例 PingReply reply = pingSender.Send(ipStr, timeout, buffer, options); if (reply.Status == IPStatus.Success) { lst_PingResult.Items.Add("答復的主機地址:" + reply.Address.ToString()); lst_PingResult.Items.Add("往返時間:" + reply.RoundtripTime); lst_PingResult.Items.Add("生存時間(TTL):" + reply.Options.Ttl); lst_PingResult.Items.Add("是否控制數據包的分段:" + reply.Options.DontFragment); lst_PingResult.Items.Add("緩沖區大小:" + reply.Buffer.Length); } else lst_PingResult.Items.Add(reply.Status.ToString()); } } }