private Object theLock = new Object();
using System.Net.NetworkInformation;
private void button1_Click(object sender, EventArgs e)
{
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("172.30.2.111", timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
richTextBox1.Clear();
richTextBox1.AppendText("Address: " + reply.Address.ToString() + "n");
richTextBox1.AppendText("RoundTrip time: " + reply.RoundtripTime + "n");
richTextBox1.AppendText("Time to live: " + reply.Options.Ttl + "n");
richTextBox1.AppendText("Don't fragment: " + reply.Options.DontFragment + "n");
richTextBox1.AppendText("Buffer size: " + reply.Buffer.Length + "n");
}
else
{
richTextBox1.Clear();
richTextBox1.AppendText("Error: " + reply.Status.ToString());
}
}
개꼬장



