■ DNS 조사하기

----------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System;

using System.Net;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 조회 버튼 클릭시 처리하기 - searchButton_Click(sender, e)

 

        /// <summary>

        /// 조회 버튼 클릭시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void searchButton_Click(object sender, EventArgs e)

        {

            string hostName = null;

 

            if(this.urlAddressTextBox.Text.Contains("://"))

            {

                hostName = this.urlAddressTextBox.Text.Replace("http://", string.Empty);

            }

            else

            {

                hostName = this.urlAddressTextBox.Text;

            }

 

            try

            {

                IPHostEntry ipHostEntry = Dns.GetHostEntry(hostName);

 

                IPAddress[] ipAddressArray = ipHostEntry.AddressList;

 

                if(this.listBox.Items.Count > 0)

                {

                    this.listBox.Items.Clear();

                }

 

                foreach(IPAddress ipAddress in ipAddressArray)

                {

                    this.listBox.Items.Add(ipAddress);

                }

            }

            catch(Exception exception)

            {

                MessageBox.Show(exception.ToString(), "ERROR",  MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

        }

 

        #endregion

    }

}

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요