C#实现根据域名查询ip实例(原创)

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 kgdiwss 的 blog


using system;
using system.net;
using system.net.sockets;

namespace getipbydomain
{
 /// <summary>
 /// class1 的摘要说明。
 /// </summary>
 class class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [stathread]
  static void main(string[] args)
  {
   //
   // todo: 在此处添加代码以启动应用程序
   //

   if(args.length <= 0)
   {
    console.write("\ngetipbydomain v1.0 by ∮明天去要饭 qq:305725744\n");
    console.write("usage:\n");
    console.write("  getipbydomain.exe <domain>\n");
    console.write("example:\n");
    console.write("  getipbydomain.exe www.toempire.com");
   }
   else
   {
    string strdomain = args[0].tostring();
    iphostentry hostentry = dns.resolve(strdomain);
    ipendpoint ipendpoint = new ipendpoint( hostentry.addresslist[0],0);
    //这就是你想要的
    string ipaddress = ipendpoint.address.tostring();
    console.write(ipaddress);
   }
  }
 }
}

我只是简单的实现一下,有兴趣的朋友可以改改bug。

本文关键:C#实现根据域名查询ip实例(原创)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top