当前位置: 移动技术网 > IT编程>开发语言>c# > C#域名解析简单实现方法

C#域名解析简单实现方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例讲述了c#域名解析简单实现方法。分享给大家供大家参考。具体实现方法如下: using system; using system.collections.

本文实例讲述了c#域名解析简单实现方法。分享给大家供大家参考。具体实现方法如下:

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#程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网