2012年3月26日 星期一

[C#] IP,Ping

CMD 下的 Ping 工具一直是很簡便的 網路連線偵測工具,本範例是使用

Net.framework 2 的 Ping 類別 來達成目的。

 

專案下載

KM-000

private void button1_Click(object sender, EventArgs e)
        {
            Ping p1 = new Ping();
            p1.PingCompleted += new PingCompletedEventHandler(this.PingCompletedCallBack);
            if (textBox1.Text.Trim().Length == 0)
            {
                return;
            }
            p1.SendAsync(textBox1.Text.Trim(), null);
        }

private void PingCompletedCallBack(object sender, PingCompletedEventArgs e)
        {
            listBox1.Items.Clear();

            if (e.Cancelled)
            {
                listBox1.Items.Add("Ping Canncel");
                return;
            }

            if (e.Error != null)
            {
                listBox1.Items.Add("e.Error.Message");
                return;
            }

            PingReply reply = e.Reply;
            listBox1.Items.Add(reply.Address + " " + reply.Status.ToString());
            if (reply.Status == IPStatus.Success)
            {
                listBox1.Items.Add("RoundTrip time:" + reply.RoundtripTime);
                listBox1.Items.Add("Time to live:"+reply.Options.Ttl);
                listBox1.Items.Add("Don't fragment:"+reply.Options.DontFragment);
                listBox1.Items.Add("Buffer size:"+reply.Buffer.Length);
            }
        }

1 則留言:

  1. Slot Machines & Video Games at JSMH
    JSMH has partnered with JMS Gaming to 남양주 출장마사지 create a 이천 출장마사지 game 경주 출장안마 for you, 거제 출장안마 JSMH's latest innovative game, JSMH is a 동해 출장마사지 brand new, original, and fully immersive,

    回覆刪除