chuichui 发表于 2006-5-31 09:02:41

请问如何用c实现dns解析?

主要是不知道怎么得到dns服务器地址!

paulmeng 发表于 2007-1-3 15:24:14

在你的机器上有的啊,就是在TCP/IP的属性中啊就是DNS服务器的IP

edust 发表于 2007-6-1 13:25:45

ipconfig /all
就可以看到了

钉子 发表于 2007-6-1 23:05:52

编程已经超过我的认知了。帮不上忙。

devil1170 发表于 2007-6-11 10:13:51

使用函数 dns.gethostname()就可以了的,新建一个解决方案,命名为 getDnsName
具体的代码如下(C#):
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace getDnsName
{
    class Program
    {
      static void Main(string[] args)
      {
            string name = Dns.GetHostName();
            Console.WriteLine("主机名字:{0}", name);
            IPHostEntry me = Dns.GetHostByName(name);
            foreach (IPAddress ip in me.AddressList)
            {
                Console.WriteLine("IP地址:{0}", ip.ToString());
                Console.Read();

            }
      }
    }
}

测试成功!
页: [1]
查看完整版本: 请问如何用c实现dns解析?