获取与IP相关联的所有DNS记录相关联、IP、DNS

由网友(别人的温柔)分享简介:背景 下面code返回给定的别名或主机的IPv4地址:[System.Net.Dns] :: GetHostAddresses('someDnsName')。IPAddressToString The following code returns the IPv4 address of a given alia...

背景

下面code返回给定的别名或主机的IPv4地址: [System.Net.Dns] :: GetHostAddresses('someDnsName')。IPAddressToString

The following code returns the IPv4 address of a given alias or host: [System.Net.Dns]::GetHostAddresses('someDnsName').IPAddressToString

下面code返回的IP主机名(CNAME)和别名: [System.Net.Dns] :: GetHostByAddress('172.12.34.56')

The below code returns the HostName (CName) and aliases of an IP: [System.Net.Dns]::GetHostByAddress('172.12.34.56')

我会因此指望什么这对 GetHostAddresses 返回一个IP上市的主机名或呼叫 GetHostByAddress (或至少该项目的FQDN被列出)。 即我期待下面的查询结果返回true

I'd therefore expect anything which returns an IP on GetHostAddresses to be listed under the HostName or Aliases of a call to GetHostByAddress (or at least for the FQDN of that item to be listed). i.e. I'd expect the result of the below query to return true

cls
$name = 'someName'
$fqdn = [System.Net.Dns]::GetHostEntry($name).HostName 
$ip = [System.Net.Dns]::GetHostAddresses($fqdn).IPAddressToString
$result = [System.Net.Dns]::GetHostByAddress($ip) 

#this is the result I'd expect to be true
($result.HostName -eq $fqdn) -or ($result.Aliases -contains $fqdn)

#here's additional info to aid in sense checking
"Name: $name"
"FQDN: $fqdn"
"IP: $ip"
"Result: "
(" - HostName: {0}" -f $result.HostName)
" - Aliases: " 
($result | select -ExpandProperty Aliases) | %{("`t{0}" -f $_)}

不过也有少数A记录这些行为不以这种方式。 这可能是DNS对我而言的一种误解,DNS在我的公司的配置错误(这是因为我在写这个剧本的DNS异常,我们发现了2台服务器在同一个IP,所以我想查别人),还是其他什么东西......

However there are a few A Records which are not behaving in this way. This may be a misunderstanding of DNS on my part, a misconfiguration of DNS at my company (it's because of DNS anomalies that I'm writing this script; we found 2 servers on the same IP; so I want to check for others), or something else...

问题

有没有办法列出与给定的IP地址相关联的所有DNS名称? 即,使得任何来自 GetHostAddresses 返回一个IP将被列在返回的IP地址反向查找的结果?

Is there a way to list all DNS names associated with a given IP address? i.e. such that anything which returns an IP from GetHostAddresses will be listed in the results of a reverse lookup on the returned IP address?

推荐答案

获取与给定的IP地址相关联的所有名称的肯定列表是不可行的,当你正在寻找在全球范围内,因为任何DNS管理员可以定义记录在他们的区域的任何IP地址。举例来说,我可以很容易地定义了一条A记录 myoverflow.planetcobalt.net。指向 stackoverflow.com IP地址198.252 .206.16。

Getting a definite list of all names associated with a given IP address is not feasible when you're looking at the global scope, because any DNS admin can define a record for any IP address in their zone. For instance I could easily define an A record myoverflow.planetcobalt.net. pointing to the stackoverflow.com IP address 198.252.206.16.

这是不太不可能的,如果你减少的范围,只是你的组织。但是,你仍然需要枚举的所有的正向查找在组织的DNS服务器区域,并检查每个A记录的地址。答案到 ServerFault问题你找到了这样做区域枚举。您需要DNS管理员特权,虽然。

It's less impossible if you're reducing the scope to just your organization. However, you still need to enumerate all forward lookup zones on your organization's DNS servers and check the address of each A record. The answers to the ServerFault question you found do this zone enumeration. You need DNS admin privileges for it, though.

之所以这样变得如此复杂的是,技术上有之间的正向和反向查找区域没有关系。有没有技术要求的任何一个记录有在所有任何PTR记录(不太匹配的)。你可以有两个记录

The reason why this gets so complicated is that technically there's no relation between forward and reverse lookup zones. There's no technical requirement for any A record to have any PTR record at all (much less a matching one). You can have two records

foo.example.com.             A    192.168.23.42

17.13.113.10.in-addr.arpa.  PTR  foo.example.com.

使用没有问题。或者多个A记录,没有PTR记录。或者PTR记录,没有A记录。

with no problem. Or multiple A records with no PTR record. Or PTR records with no A record.

微软的DNS服务器允许您使用A记录PTR记录相关联,但是这只是一个方便的功能。此外,还有在域名系统,对这个关联没有任何技术要求。

Microsoft's DNS server allows you to associate a PTR record with an A record, but that's just a convenience feature. Again, there's no technical requirement in the Domain Name System for this association.