Form1.cs
上传用户:jsz11269
上传日期:2017-01-14
资源大小:450k
文件大小:2k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net;
  9. namespace UseDNS
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.             lbHost.Text = Dns.GetHostName();
  20.             IPHostEntry Host = Dns.GetHostEntry(lbHost.Text);
  21.             //IPHostEntry Host = Dns.GetHostByName(lbHost.Text);
  22.             lbHost.Text = "本机域名为:" + lbHost.Text + ",IP地址为:" + Host.AddressList[0].ToString();
  23.         }
  24.         private void getDomain_Click(object sender, EventArgs e)
  25.         {
  26.             try
  27.             {
  28.                 if (tbIP.Text != "")
  29.                 {
  30.                     IPHostEntry Host = Dns.GetHostEntry(lbHost.Text); //Dns.GetHostByAddress(tbIP.Text);
  31.                     tbDomain.Text = Host.HostName;
  32.                 }
  33.             }
  34.             catch (Exception ex)
  35.             {
  36.                 MessageBox.Show(ex.Message.ToString());
  37.             }
  38.         }
  39.         private void btnGetIP_Click(object sender, EventArgs e)
  40.         {
  41.             try
  42.             {
  43.                 if (tbDomain.Text != "")
  44.                 {
  45.                     IPHostEntry Host = Dns.GetHostEntry(tbDomain.Text);
  46.                     tbIP.Text = Host.AddressList[0].ToString();
  47.                 }
  48.             }
  49.             catch (Exception ex)
  50.             {
  51.                 MessageBox.Show(ex.Message.ToString());
  52.             }
  53.         }
  54.     }
  55. }