Dns NameServer Query C#

本文关键字:Query NameServer Dns | 更新日期: 2023-09-27 18:10:43

我正试图查询一个网址,并获得当前非缓存的结果,如根名称服务器和管理联系电子邮件。你能告诉我一个关于如何实现这一点的示例代码指南。谢谢汤米

Dns NameServer Query C#

看起来你需要WhoIs查找。DNS查找不返回管理电子邮件。DNS Lookup返回A、CNAME、MX、TXT等DNS记录。

对于whois查询,您需要从域所属的whois服务器上查询whois数据。下面的代码片段使用NetworkStream读取。com域名的WhoIs数据:

// Create new socket object
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
string query = "mydomain.com";
NetworkStream nst;
try
{
    IPEndPoint endPoint = new IPEndPoint("whois.internic.net", 43)
    socket.Connect(endPoint);
    nst = new NetworkStream(socket, true);
    string str;
    StreamWriter writer = new StreamWriter(nst);
    writer.WriteLine(query);
    writer.Flush();
    StringBuilder builder = new StringBuilder();
    StreamReader reader = new StreamReader(nst);
    while ((str = reader.ReadLine()) != null)
    {
        builder.Append(str);
        builder.Append(
#if !NETCF
            Environment.NewLine
#else
            "'r'n"                        
#endif
            );
    }
    result = builder.ToString();
}
finally
{
    if (nst != null)
        nst.Close();
    socket.Close();
}