查询DNS别名 [英] querying for dns aliases

查看:162
本文介绍了查询DNS别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了代码从msdn站点(包含下面的代码),看起来它将返回给定服务器的所有dns别名。我已经在cosole应用中实现了该代码,该代码应允许我输入服务器的主机名,并且应返回所有dns别名。我在我们的域中输入已知具有别名的服务器的主机名(我可以ping通主机和别名,并且它们都解析为相同的IP),但是此代码找不到别名。显然,我对dns别名和/或代码缺乏了解...请教育我...

I found some code from the msdn site (Code included below), which looks like it will return all dns aliases for a given server. I've implemented the code in a cosole app, which should allow me to enter the host name of a server and it should return all dns alias names. I enter the host name of a server in our domain known to have aliases (I can ping the host and the aliases and they all resolve to the same IP), but this code does not find the alias names. Obvously my understanding of dns aliases and/or the code is lacking... please educate me...

static void Main(string[] args)
{
    Console.Write("Host? (Enter for local): ");
    string strHost = Console.ReadLine();
    if (strHost.Trim().Length == 0)
    {
        strHost = System.Net.Dns.GetHostName();
    }

    try
    {
        //System.Net.IPAddress hostIPAddress = System.Net.IPAddress.Parse(strHost);
        System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByName(strHost);//.GetHostByAddress(hostIPAddress);
        // Get the IP address list that resolves to the host names contained in 
        // the Alias property.
        System.Net.IPAddress[] address = hostInfo.AddressList;
        // Get the alias names of the addresses in the IP address list.
        String[] alias = hostInfo.Aliases;

        Console.WriteLine("Host name : " + hostInfo.HostName);
        Console.WriteLine("\nAliases :");
        for (int index = 0; index < alias.Length; index++)
        {
            Console.WriteLine(alias[index]);
        }
        Console.WriteLine("\nIP address list : ");
        for (int index = 0; index < address.Length; index++)
        {
            Console.WriteLine(address[index]);
        }
    }
    catch (System.Net.Sockets.SocketException e)
    {
        Console.WriteLine("SocketException caught!!!");
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }
    catch (FormatException e)
    {
        Console.WriteLine("FormatException caught!!!");
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }
    catch (ArgumentNullException e)
    {
        Console.WriteLine("ArgumentNullException caught!!!");
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine("Exception caught!!!");
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }

    Console.WriteLine("Any key to continue...");
    Console.ReadKey();
}


推荐答案

对于DNS名称,仅当您查询的名称具有CNAME记录时,别名列表才会为非空;然后,别名列表将为您提供所有必须解析才能获得最终名称的CNAME。

For a DNS name, the list of aliases will only be non-empty if the name you are querying has a CNAME record; then, the alias list will give you all CNAMEs that had to be resolved in order to get the ultimate name.

请考虑以下问题:


  • 不可能(即协议不支持)找到给定名称的所有CNAME。这是不可行的,因为这将需要搜索整个全局DNS。

  • 别名不仅可能由CNAME发生,而且也可能由具有相同地址(A)记录的多个主机名发生。在这种情况下,不是一个是另一个的别名,而是它们指向相同的IP地址。同样,该协议不支持查找IP地址的所有A记录(尽管可能会进行一些反向查找)。

这篇关于查询DNS别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆