private void button_Ping_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 = 3000;
PingReply reply = pingSender.Send(textBox_TargetHost.Text.Trim(), timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
}
else
{
Console.WriteLine(string.Format("[{0}] Ping timeout!",DateTime.Now.ToString()));
}
}
.net里的System.Net.NetworkInformation.Ping的简单使用
最新推荐文章于 2024-08-24 08:01:24 发布