一个dnslookuo例子。。。

80酷酷网    80kuku.com

  testform.cs
------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;

namespace testagain
{
    /// <summary>
    /// Summary description for testform.
    /// </summary>
    public class testform : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox txt_Domain;
        private System.Windows.Forms.Button btn_Find;
        private System.Windows.Forms.Label lbl_result;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public testform(Form f_MainForm)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            this.MdiParent = f_MainForm;

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                if( disposing )
                {
                    if(components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose( disposing );
            }

        #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.txt_Domain = new System.Windows.Forms.TextBox();
                this.lbl_result = new System.Windows.Forms.Label();
                this.btn_Find = new System.Windows.Forms.Button();
                this.SuspendLayout();
                //
                // txt_Domain
                //
                this.txt_Domain.Location = new System.Drawing.Point(104, 56);
                this.txt_Domain.Name = "txt_Domain";
                this.txt_Domain.Size = new System.Drawing.Size(240, 21);
                this.txt_Domain.TabIndex = 1;
                this.txt_Domain.Text = "www.yahoo.com";
                //
                // lbl_result
                //
                this.lbl_result.Location = new System.Drawing.Point(112, 112);
                this.lbl_result.Name = "lbl_result";
                this.lbl_result.Size = new System.Drawing.Size(336, 40);
                this.lbl_result.TabIndex = 0;
                //
                // btn_Find
                //
                this.btn_Find.Location = new System.Drawing.Point(360, 56);
                this.btn_Find.Name = "btn_Find";
                this.btn_Find.Size = new System.Drawing.Size(72, 24);
                this.btn_Find.TabIndex = 2;
                this.btn_Find.Text = "DNSLookUp";
                this.btn_Find.Click += new System.EventHandler(this.btn_Find_Click);
                //
                // testform
                //
                this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
                this.ClientSize = new System.Drawing.Size(536, 329);
                this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                              this.btn_Find,
                                                                              this.txt_Domain,
                                                                              this.lbl_result});
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.Name = "testform";
                this.ShowInTaskbar = false;
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                this.Text = "testform";
                this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                this.ResumeLayout(false);

            }
        #endregion

            private void btn_Find_Click(object sender, System.EventArgs e)
            {
                lbl_result.Text = "正在解析中,请稍候...";
                IPHostEntry ip = Dns.GetHostByName(this.txt_Domain.Text);
                IPAddress[] ipaddr = ip.AddressList;

                for (int i=0;i<ipaddr.Length;i++)
                {
                    lbl_result.Text += "\r\n" + ipaddr[i].ToString();
                }
            }
        }
}
 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: