ping的使用示例,需要引用System.Net.NetworkInformation;
如:using System.Net.NetworkInformation;
代码示例如下
Ping PingInfo = new Ping();
PingOptions PingOpt = new PingOptions();
PingOpt.DontFragment = true;
string myInfo = "hyworkhyworkhyworkhyworkhyworkhywork";
byte[] bufferInfo = Encoding.ASCII.GetBytes(myInfo);
int TimeOut = 120;
PingReply reply = PingInfo.Send(this.textBox1.Text, TimeOut, bufferInfo, PingOpt);
if (reply.Status == IPStatus.Success)
{
this.textBox2.Text = reply.RoundtripTime.ToString();
this.textBox3.Text = reply.Options.Ttl.ToString();
this.textBox4.Text = (reply.Options.DontFragment ? "发生分段" : "没有发生分段");
this.textBox5.Text = reply.Buffer.Length.ToString();
}
else
{
MessageBox.Show("无法Ping通");
}
**************************************************************************************************************