2014/10/13

C# Ping a hostname on the network

Code:
using System;
using System.Net.NetworkInformation;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            Ping ping = new Ping();
            PingReply reply = ping.Send("IP");
            if (reply.Status == IPStatus.Success)
            {
                MessageBox.Show("ok");
            }   
        }
    }
}

執行結果:


參考資料:
http://msdn.microsoft.com/en-us/library/a63bsyf0.aspx