请问如何用c实现dns解析?
主要是不知道怎么得到dns服务器地址! *** 作者被禁止或删除 内容自动屏蔽 *** 在你的机器上有的啊,就是在TCP/IP的属性中啊就是DNS服务器的IP ipconfig /all就可以看到了 编程已经超过我的认知了。帮不上忙。 使用函数 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]
