【问题标题】:.NET GetHostByAddress aliases only showing up 8 entries.NET GetHostByAddress 别名仅显示 8 个条目
【发布时间】:2012-10-23 17:11:09
【问题描述】:

我需要从我们的 DNS 服务器输入的单个 IP 地址中获取每个 CNAME 记录。
当我查找时:

[System.Net.Dns]::GetHostByAddress("81.95.243.81").Aliases

它只给了我相同的 8 个别名作为回报:

botexshop.dk
bisamba.dk
nordsoenoceanarium.dk
www.brandingcommunity.com
botexhome.dk
botexudstyr.dk
botexjylland.dk
marineacademy.dk

但我知道IP地址有超过69条CNAME记录(请看这里:Toolbox | DNSstuff | Reverse DNS Lookup Results for 81.95.243.81

为什么GetHostByAddress 总是只返回相同的 8 个别名?以及如何获取所有 CNAME?

【问题讨论】:

  • GetHostBYAddress 已过时:msdn.microsoft.com/en-us/library/sbetxfzt.aspx
  • 我知道,但 GetHostEntry 根本不返回任何别名。 [System.Net.Dns]::GetHostEntry("81.95.243.81").Aliases 什么也不返回。那么我怎样才能从您的回答中受益呢?
  • 这不是答案:显然是评论。
  • 由于我无法对 cme​​ts 进行注释,因此我对问题进行了注释 - 我认为取笑试图帮助您的人是错误

标签: c# .net powershell dns


【解决方案1】:

System.Net.Dns 在很多方面都非常缺乏。我见过一些人甚至编写成熟的 DNS 解析器来获得他们需要的东西。

我知道这并不能完全回答你的问题,但是这个函数似乎可以完成工作,但是它非常脆弱并且依赖于 nslookup 所以 YMMV:

function get-dnsaliases($ip)
{
    $ip_rev = $ip -split '\.'
    [array]::reverse($ip_rev)
    $ip_rev = $ip_rev -join '.'
    $ptr_regex = "^`t" + [regex]::escape("$ip_rev.in-addr.arpa, type = PTR, class = IN")

    $responses = nslookup -d $ip

    $foundanswer = $null
    $aliases = @()

    foreach ($response in $responses)
    {
        if($foundanswer)
        {
            if($response -match "^`tname = (?<alias>.+)$")
            {
                $aliases += $Matches.alias
            }
        }
        elseif($response -match $ptr_regex)
        {
            $foundanswer = $true
        }
    }
    return $aliases
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多