반응형

* C# IP Ping Check 예제...

전체 소스 코드

Form1.cs

 

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;

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

        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {

                System.Net.NetworkInformation.Ping Pping = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();

                options.DontFragment = true;

                //전송할 데이터를 입력
                string strData = "123123123";
                byte[] buffer = ASCIIEncoding.ASCII.GetBytes(strData);

                int iTimeout = 120;
                //IP 주소를 입력
                System.Net.NetworkInformation.PingReply PRreply = Pping.Send(System.Net.IPAddress.Parse(TextBox1.Text), iTimeout, buffer, options);

                if (PRreply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    MessageBox.Show("Ping Check Success...", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }

                else
                {
                    MessageBox.Show("Ping Check Failed...", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }

            catch(Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }
        }
    }
}

 

*예제 결과

 

 

 

반응형

+ Recent posts