测试IP代码
TextBox2.Text = ""; //需要测试的IP
Ping pingSender = new Ping(); //创建PING实例
//
为设置PING参数
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(TextBox1.Text, timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
//获取相关网络连接信息
TextBox2.Text += "Address:" + reply.Address.ToString() + "/r/n";
TextBox2.Text += "RoundTrip time:" + reply.RoundtripTime + "/r/n";
TextBox2.Text += "Time to live:" + reply.Options.Ttl + "/r/n";
TextBox2.Text += "Don't fragment:" + reply.Options.DontFragment + "/r/n";
TextBox2.Text += "Buffer size:" + reply.Buffer.Length + "/r/n";
}
else
{
TextBox2.Text = "无法连接!";
}