C#域名解析簡單實現(xiàn)方法
更新時間:2015年07月03日 10:10:56 作者:程序猴
這篇文章主要介紹了C#域名解析簡單實現(xiàn)方法,可實現(xiàn)針對域名解析顯示出主機名、IP地址、別名等功能,需要的朋友可以參考下
本文實例講述了C#域名解析簡單實現(xiàn)方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace test1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonDns_Click(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
//解析主機名
IPHostEntry IPinfo = Dns.GetHostEntry(textBox1.Text);
//清空列表框
listBox1.Items.Clear();
listBox2.Items.Clear();
//顯示IP地址
foreach (IPAddress IP in IPinfo.AddressList)
{
listBox1.Items.Add(IP.ToString());
}
//顯示別名
foreach (string alias in IPinfo.Aliases)
{
listBox2.Items.Add(alias);
}
//顯示主機名
textBox2.Text = IPinfo.HostName;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
希望本文所述對大家的C#程序設計有所幫助。
相關(guān)文章
c#使用linq技術(shù)創(chuàng)建xml文件的小例子
c#使用linq技術(shù)創(chuàng)建xml文件的小例子,需要的朋友可以參考一下2013-03-03
C# WinForm中Panel實現(xiàn)用鼠標操作滾動條的實例方法
由于在WinForm中Panel不能直接響應鼠標的滾動事件,只好采用捕獲窗體的滾動事件。2013-03-03

