using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net.NetworkInformation;

namespace Ex09_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                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)
                {
                    textBox2.Text = reply.RoundtripTime.ToString();
                    textBox3.Text = reply.Options.Ttl.ToString();
                    textBox4.Text = (reply.Options.DontFragment ? "发生分段" : "没有发生分段");
                    textBox5.Text = reply.Buffer.Length.ToString();
                    textBox6.Text = reply.Status.ToString();

                }
                else
                {
                    MessageBox.Show(this, "无法连接到指定网络，即Ping不通！", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ey)
            {
                MessageBox.Show(ey.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
