c#dns解析示例

2007-11-22 16:05

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
namespace WindowsApplication2
{

/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
   private System.Windows.Forms.Label label1;
   private System.Windows.Forms.Label label2;
   private System.Windows.Forms.TextBox ip1;
   private System.Windows.Forms.TextBox domain1;
   private System.Windows.Forms.TextBox domain2;
   private System.Windows.Forms.Label label3;
   private System.Windows.Forms.TextBox ip2;
   private System.Windows.Forms.Button button1;
   private System.Windows.Forms.Button button2;
   private System.Windows.Forms.Label label4;
   private System.Windows.Forms.Label label5;
   /// <summary>
   /// 必需的设计器变量。
   /// </summary>
   /// 
  
   private System.ComponentModel.Container components = null;

   public Form1()
   {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();

    //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
   }

   /// <summary>
   /// 清理所有正在使用的资源。
   /// </summary>
   protected override void Dispose( bool disposing )
   {
    if( disposing )
    {
     if (components != null) 
     {
      components.Dispose();
     }
    }
    base.Dispose( disposing );
   }

   #region Windows 窗体设计器生成的代码
   /// <summary>
   /// 设计器支持所需的方法 - 不要使用代码编辑器修改
   /// 此方法的内容。
   /// </summary>
   private void InitializeComponent()
   {
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.ip1 = new System.Windows.Forms.TextBox();
    this.domain1 = new System.Windows.Forms.TextBox();
    this.domain2 = new System.Windows.Forms.TextBox();
    this.label3 = new System.Windows.Forms.Label();
    this.ip2 = new System.Windows.Forms.TextBox();
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.label4 = new System.Windows.Forms.Label();
    this.label5 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(136, 16);
    this.label1.Name = "label1";
    this.label1.TabIndex = 0;
    this.label1.Text = "域名解析";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(144, 56);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(72, 16);
    this.label2.TabIndex = 1;
    this.label2.Text = "IP--〉域名";
    // 
    // ip1
    // 
    this.ip1.Location = new System.Drawing.Point(16, 56);
    this.ip1.Name = "ip1";
    this.ip1.Size = new System.Drawing.Size(120, 21);
    this.ip1.TabIndex = 2;
    this.ip1.Text = "textBox1";
    // 
    // domain1
    // 
    this.domain1.Location = new System.Drawing.Point(224, 56);
    this.domain1.Name = "domain1";
    this.domain1.Size = new System.Drawing.Size(144, 21);
    this.domain1.TabIndex = 3;
    this.domain1.Text = "textBox2";
    // 
    // domain2
    // 
    this.domain2.Location = new System.Drawing.Point(16, 104);
    this.domain2.Name = "domain2";
    this.domain2.Size = new System.Drawing.Size(120, 21);
    this.domain2.TabIndex = 4;
    this.domain2.Text = "textBox1";
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(144, 104);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(64, 23);
    this.label3.TabIndex = 5;
    this.label3.Text = "域名->ip";
    // 
    // ip2
    // 
    this.ip2.Location = new System.Drawing.Point(224, 104);
    this.ip2.Name = "ip2";
    this.ip2.Size = new System.Drawing.Size(144, 21);
    this.ip2.TabIndex = 6;
    this.ip2.Text = "textBox1";
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(384, 56);
    this.button1.Name = "button1";
    this.button1.TabIndex = 7;
    this.button1.Text = "确定";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.Location = new System.Drawing.Point(384, 104);
    this.button2.Name = "button2";
    this.button2.TabIndex = 8;
    this.button2.Text = "确定";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // label4
    // 
    this.label4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(128)));
    this.label4.Location = new System.Drawing.Point(168, 224);
    this.label4.Name = "label4";
    this.label4.Size = new System.Drawing.Size(248, 23);
    this.label4.TabIndex = 9;
    this.label4.Text = "网络05玄魂制作";
    // 
    // label5
    // 
    this.label5.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(255)), ((System.Byte)(255)));
    this.label5.Location = new System.Drawing.Point(168, 184);
    this.label5.Name = "label5";
    this.label5.Size = new System.Drawing.Size(248, 23);
    this.label5.TabIndex = 10;
    this.label5.Text = "运行环境framework1.1以上";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(472, 273);
    this.Controls.Add(this.label5);
    this.Controls.Add(this.label4);
    this.Controls.Add(this.button2);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.ip2);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.domain2);
    this.Controls.Add(this.domain1);
    this.Controls.Add(this.ip1);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.label1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false);

   }
   #endregion

   /// <summary>
   /// 应用程序的主入口点。
   /// </summary>
   [STAThread]
   
  
   static void Main() 
   {
    Application.Run(new Form1());
   }

   private void Form1_Load(object sender, System.EventArgs e)
   {
  
   }

   private void button1_Click(object sender, System.EventArgs e)
   {
    string adr=" ";
    adr=ip1.Text;
    IPHostEntry IPHost = Dns.Resolve(adr);
   string names = IPHost.HostName;
    domain1.Text = names;
   }

   private void button2_Click(object sender, System.EventArgs e)
   {
    string name=" ",adr=" ";
    name = domain2.Text;
    IPHostEntry IPHost = Dns.Resolve(name);
    IPAddress[] addr= IPHost.AddressList;
    for(int i=0;i<addr.Length;i++)
    {
     adr+=addr[i];

    }
ip2.Text = adr;

   }
}
}


本文转自悬魂博客园博客,原文链接:http://www.cnblogs.com/xuanhun/archive/2010/02/03/1662420.html,如需转载请自行联系原作者
上一篇:说说阿里增量计算框架Galaxy


下一篇:深入研究Java类加载机制