C # dns resolution example

Source: Internet
Author: User

Using System;
Using System. Drawing;
Using System. Collections;
Using System. ComponentModel;
Using System. Windows. Forms;
Using System. Data;
Using System. Net;
Namespace WindowsApplication2
{

/// <Summary>
/// Summary of 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>
/// Required designer variables.
/// </Summary>
///

Private System. ComponentModel. Container components = null;

Public Form1 ()
{
//
// Required for Windows Form Designer support
//
InitializeComponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </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 = "domain name resolution ";
//
// 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 --> domain name ";
//
// 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 = "Domain Name-> 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 = "OK ";
This. button1.Click + = new System. EventHandler (this. button#click );
//
// Button2
//
This. button2.Location = new System. Drawing. Point (384,104 );
This. button2.Name = "button2 ";
This. button2.TabIndex = 8;
This. button2.Text = "OK ";
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 = "Network 05 xuanhun production ";
//
// 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 = "runtime environment framework1.1 or above ";
//
// 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. form#load );
This. resumelayout (false );

}
# Endregion

/// <Summary>
/// Main entry point of the application.
/// </Summary>
[Stathread]


Static void main ()
{
Application. Run (New form1 ());
}

Private void form1_load (Object sender, system. eventargs E)
{

}

Private void button#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;

}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.