特定域的 DNS 解析失败。域与 nslookup 一起使用
DNS resolve failing for specific domains. Domains work with nslookup
我想要发生的事情: 将域作为字符串传递给方法,并在域解析时将其设置为 return true。如果没有,则为假。基本目标是查看域是否存在。
会发生什么: 最有效的域字符串 return 正确。然而,有些 return 尽管使用 nslookup 解决了错误。
我不明白为什么某些域在使用命令提示符 nslookup 和 nslookup 站点时看起来不错但无法解析。 (我用过https://centralops.net/ , http://www.kloth.net/services/nslookup.php , and http://network-tools.com/nslook/)
方法(C#):
//no blank domains
public bool CheckDomain(string sDomain)
{
if (string.IsNullOrWhiteSpace(sDomain)) return false;
for (int i = 1; i <= mQueryRetry; i++)
{
try
{
System.Net.IPAddress dnsCli = System.Net.IPAddress.Parse("8.8.8.8")
DnsClient myClient = new DnsClient(dnsCli);
DnsMessage dnsMessage = myClient.Resolve(ARSoft.Tools.Net.DomainName.Parse(sDomain), RecordType.A);
if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain)))
{
throw new Exception("DNS request failed");
}
else
{
foreach (DnsRecordBase dnsRecord in dnsMessage.AnswerRecords)
{
ARecord aRecord = dnsRecord as ARecord;
if (aRecord != null)
{
return true;
}
}
}
}
catch (Exception ex)
{
// Back off and try again after 1 seconds
if (i != mQueryRetry)
{
System.Threading.Thread.Sleep(1000);
}
else
{
System.Diagnostics.Trace.WriteLine(string.Format("Domain: {0} error: {1}", sDomain, ex.Message));
}
}
}
System.Diagnostics.Trace.Flush();
return false;
}
如果你打算测试它,我建议用 one of these. 替换 dnsCli
IPAddress 我已经把 google DNS 服务器的 IP 留在那里作为例子,但我在我的生产代码中使用我公司的 DNS 服务器。我发现更改 DNS 服务器绝不会影响该方法的行为。
我正在为 DnsClient
、DnsMessage
、DomainName
、DnsRecordBase
和 [ 使用最新版本的 Arsoft.Tools.Net (2.2.8) =17=]、classes/objects。我们在旧版本 (1.8.1) 上遇到了同样的问题。
一些无法解析的域是:
appraisallinks-amc.com
resurgenstech.com
orpheusvr.com
trovvit.com
附加信息:我尝试了一些长得可笑的查询超时限制,超过 5 分钟,但它们没有任何区别。因此,我确定这不是超时问题。
"you can try and use a different library, the DnsClient (nuget) instead, see dnsclient.michaco.net. The domain names in question seem to work just fine " -
@MichaC
问题实际上是我使用的 Arsoft.Tools.Net 库。切换到 DnsClient.Net 解决了问题。
我想要发生的事情: 将域作为字符串传递给方法,并在域解析时将其设置为 return true。如果没有,则为假。基本目标是查看域是否存在。
会发生什么: 最有效的域字符串 return 正确。然而,有些 return 尽管使用 nslookup 解决了错误。
我不明白为什么某些域在使用命令提示符 nslookup 和 nslookup 站点时看起来不错但无法解析。 (我用过https://centralops.net/ , http://www.kloth.net/services/nslookup.php , and http://network-tools.com/nslook/)
方法(C#):
//no blank domains
public bool CheckDomain(string sDomain)
{
if (string.IsNullOrWhiteSpace(sDomain)) return false;
for (int i = 1; i <= mQueryRetry; i++)
{
try
{
System.Net.IPAddress dnsCli = System.Net.IPAddress.Parse("8.8.8.8")
DnsClient myClient = new DnsClient(dnsCli);
DnsMessage dnsMessage = myClient.Resolve(ARSoft.Tools.Net.DomainName.Parse(sDomain), RecordType.A);
if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain)))
{
throw new Exception("DNS request failed");
}
else
{
foreach (DnsRecordBase dnsRecord in dnsMessage.AnswerRecords)
{
ARecord aRecord = dnsRecord as ARecord;
if (aRecord != null)
{
return true;
}
}
}
}
catch (Exception ex)
{
// Back off and try again after 1 seconds
if (i != mQueryRetry)
{
System.Threading.Thread.Sleep(1000);
}
else
{
System.Diagnostics.Trace.WriteLine(string.Format("Domain: {0} error: {1}", sDomain, ex.Message));
}
}
}
System.Diagnostics.Trace.Flush();
return false;
}
如果你打算测试它,我建议用 one of these. 替换 dnsCli
IPAddress 我已经把 google DNS 服务器的 IP 留在那里作为例子,但我在我的生产代码中使用我公司的 DNS 服务器。我发现更改 DNS 服务器绝不会影响该方法的行为。
我正在为 DnsClient
、DnsMessage
、DomainName
、DnsRecordBase
和 [ 使用最新版本的 Arsoft.Tools.Net (2.2.8) =17=]、classes/objects。我们在旧版本 (1.8.1) 上遇到了同样的问题。
一些无法解析的域是:
appraisallinks-amc.com
resurgenstech.com
orpheusvr.com
trovvit.com
附加信息:我尝试了一些长得可笑的查询超时限制,超过 5 分钟,但它们没有任何区别。因此,我确定这不是超时问题。
"you can try and use a different library, the DnsClient (nuget) instead, see dnsclient.michaco.net. The domain names in question seem to work just fine " - @MichaC
问题实际上是我使用的 Arsoft.Tools.Net 库。切换到 DnsClient.Net 解决了问题。