Form1.cs
上传用户:jsz11269
上传日期:2017-01-14
资源大小:450k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- namespace UseDNS
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- lbHost.Text = Dns.GetHostName();
- IPHostEntry Host = Dns.GetHostEntry(lbHost.Text);
- //IPHostEntry Host = Dns.GetHostByName(lbHost.Text);
- lbHost.Text = "本机域名为:" + lbHost.Text + ",IP地址为:" + Host.AddressList[0].ToString();
- }
- private void getDomain_Click(object sender, EventArgs e)
- {
- try
- {
- if (tbIP.Text != "")
- {
- IPHostEntry Host = Dns.GetHostEntry(lbHost.Text); //Dns.GetHostByAddress(tbIP.Text);
- tbDomain.Text = Host.HostName;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }
- private void btnGetIP_Click(object sender, EventArgs e)
- {
- try
- {
- if (tbDomain.Text != "")
- {
- IPHostEntry Host = Dns.GetHostEntry(tbDomain.Text);
- tbIP.Text = Host.AddressList[0].ToString();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }
- }
- }