【发布时间】:2023-03-09 04:21:01
【问题描述】:
我有 2 个 DNS 服务器(domainserverwithport.com:5356 和 domainserverwithoutport.com)我正在连接到一个查找请求。一个有端口号,而另一个没有。
没有端口号的连接并从请求中获得答案。但第二个什么也不返回。 在使用 ARSoft.Tools.Net.Core 时,我看不到使用 IP 地址和端口号实例化新 DNSClient 的选项。请问有没有办法解决这个问题?
我为没有端口号的 DNS 服务器做了以下操作。
var ip = Dns.GetHostEntry("domainserverwithoutport.com");
Console.WriteLine(ip.AddressList[0]);
var newIp = ip.AddressList[0];
IPAddress iPAddress = IPAddress.Parse(newIp.ToString());
var result = EnumDnsQuery(iPAddress.ToString(), "8.7.4.3.9.5.3.1.0.9.4.3.2.e164.arpa.4.couretech.0ceed", RecordType.Naptr, 0, 5000);
还有 EnumDnsQuery 方法
public static EnumDnsResponse EnumDnsQuery(string serverIp, string domain,
RecordType recordType, int maximumRetries = 0, int queryTimeout = QUERY_TIMEOUT_MILLISECONDS)
{
int retriesToUse = maximumRetries > 0 ? maximumRetries : 0;
DnsMessage dnsMessage = null;
TimeSpan duration = TimeSpan.Zero;
IPAddress ipAddress = IPAddress.Parse(serverIp);
DomainName domainName = DomainName.Parse(domain);
var stopwatch = new Stopwatch();
DnsClient client = new DnsClient(ipAddress, queryTimeout);
int attempts = 0;
stopwatch.Start();
while (dnsMessage == null && attempts <= retriesToUse)
{
attempts++;
dnsMessage = client.Resolve(domainName, recordType);
}
stopwatch.Stop();
string rawMessage = string.Empty;
if (dnsMessage != null && recordType == RecordType.Naptr)
{
var naptrRecords = dnsMessage.AnswerRecords.Where(x => x.GetType() == typeof(NaptrRecord))
.Select(x => (NaptrRecord)x)
.Where(x => x.Services.Equals("E2U+pstn:tel"))
.OrderByDescending(x => x.Order);
var naptrRecord = naptrRecords.FirstOrDefault();
if (naptrRecord != null)
rawMessage = naptrRecord.RegExp.Trim('!');
}
else if (dnsMessage != null && recordType == RecordType.Txt)
{
var txtRecords = dnsMessage.AnswerRecords.Where(x => x.GetType() == typeof(TxtRecord))
.Select(x => (TxtRecord)x);
var txtRecord = txtRecords.FirstOrDefault();
if (txtRecord == null)
rawMessage = txtRecord.TextData.Trim('!');
}
return new EnumDnsResponse(
dnsMessage: dnsMessage,
rawMessage: rawMessage,
totalDuration: stopwatch.Elapsed,
attempts: attempts);
}
上面的代码返回一个 DnsMessage。 但是当我为另一个需要端口号的域服务器做同样的事情时,DnsMessage 变为空。请问有没有办法解决这个问题?
【问题讨论】: