Form1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:4k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Net;
  8. namespace Wrox.ProCSharp.InternetAccess.DnsLookUp
  9. {
  10. /// <summary>
  11. /// Summary description for Form1.
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.TextBox txtBoxInput;
  17. private System.Windows.Forms.TextBox txtBoxHostName;
  18. private System.Windows.Forms.ListBox listBoxIPs;
  19. /// <summary>
  20. /// Required designer variable.
  21. /// </summary>
  22. private System.ComponentModel.Container components = null;
  23. public Form1()
  24. {
  25. //
  26. // Required for Windows Form Designer support
  27. //
  28. InitializeComponent();
  29. //
  30. // TODO: Add any constructor code after InitializeComponent call
  31. //
  32. }
  33. /// <summary>
  34. /// Clean up any resources being used.
  35. /// </summary>
  36. protected override void Dispose( bool disposing )
  37. {
  38. if( disposing )
  39. {
  40. if (components != null) 
  41. {
  42. components.Dispose();
  43. }
  44. }
  45. base.Dispose( disposing );
  46. }
  47. #region Windows Form Designer generated code
  48. /// <summary>
  49. /// Required method for Designer support - do not modify
  50. /// the contents of this method with the code editor.
  51. /// </summary>
  52. private void InitializeComponent()
  53. {
  54. this.button1 = new System.Windows.Forms.Button();
  55. this.txtBoxInput = new System.Windows.Forms.TextBox();
  56. this.txtBoxHostName = new System.Windows.Forms.TextBox();
  57. this.listBoxIPs = new System.Windows.Forms.ListBox();
  58. this.SuspendLayout();
  59. // 
  60. // button1
  61. // 
  62. this.button1.Location = new System.Drawing.Point(192, 232);
  63. this.button1.Name = "button1";
  64. this.button1.Size = new System.Drawing.Size(96, 32);
  65. this.button1.TabIndex = 0;
  66. this.button1.Text = "button1";
  67. this.button1.Click += new System.EventHandler(this.button1_Click);
  68. // 
  69. // txtBoxInput
  70. // 
  71. this.txtBoxInput.Location = new System.Drawing.Point(8, 16);
  72. this.txtBoxInput.Name = "txtBoxInput";
  73. this.txtBoxInput.Size = new System.Drawing.Size(272, 20);
  74. this.txtBoxInput.TabIndex = 1;
  75. this.txtBoxInput.Text = "textBox1";
  76. // 
  77. // txtBoxHostName
  78. // 
  79. this.txtBoxHostName.Location = new System.Drawing.Point(8, 72);
  80. this.txtBoxHostName.Name = "txtBoxHostName";
  81. this.txtBoxHostName.Size = new System.Drawing.Size(280, 20);
  82. this.txtBoxHostName.TabIndex = 2;
  83. this.txtBoxHostName.Text = "textBox2";
  84. // 
  85. // listBoxIPs
  86. // 
  87. this.listBoxIPs.Location = new System.Drawing.Point(8, 112);
  88. this.listBoxIPs.Name = "listBoxIPs";
  89. this.listBoxIPs.Size = new System.Drawing.Size(272, 108);
  90. this.listBoxIPs.TabIndex = 3;
  91. // 
  92. // Form1
  93. // 
  94. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  95. this.ClientSize = new System.Drawing.Size(292, 273);
  96. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  97.   this.listBoxIPs,
  98.   this.txtBoxHostName,
  99.   this.txtBoxInput,
  100.   this.button1});
  101. this.Name = "Form1";
  102. this.Text = "Form1";
  103. this.ResumeLayout(false);
  104. }
  105. #endregion
  106. /// <summary>
  107. /// The main entry point for the application.
  108. /// </summary>
  109. [STAThread]
  110. static void Main() 
  111. {
  112. Application.Run(new Form1());
  113. }
  114. private void button1_Click(object sender, System.EventArgs e)
  115. {
  116. try
  117. {
  118. IPHostEntry iphost = Dns.Resolve(txtBoxInput.Text);
  119. foreach (IPAddress ip in iphost.AddressList)
  120. {
  121. long ipaddress = ip.Address;
  122. listBoxIPs.Items.Add(ipaddress);
  123. listBoxIPs.Items.Add("   " + ip.ToString());
  124.                         
  125. }
  126. txtBoxHostName.Text = iphost.HostName;
  127. }
  128. catch(Exception ex)
  129. {
  130. MessageBox.Show("Unable to process the request because " +
  131. "the following problem occurred:n" + 
  132. ex.Message, "Exception occurred");
  133. }
  134. }
  135. private void button2_Click(object sender, System.EventArgs e)
  136. {
  137. }
  138. }
  139. }