如何使用 TIdDNSResolver 解析 dns?
当尝试解析 dns 时,我收到 dns 错误拒绝的查询。我的代码有错吗?您可以检查一下吗?
function Lookup(const Name: String): String;
var
X: Integer;
DNS: TIdDNSResolver;
begin
DNS:= TIdDNSResolver.Create(nil);
try
DNS.Host := 'mail.relativ.art';
DNS.WaitingTime := 5000;
DNS.QueryType:= [qtMX];
try DNS.Resolve(Name); except on E: Exception do begin writeln(E.Message); end; end;
for X:= 0 to DNS.QueryResult.Count-1 do begin
if DNS.QueryResult[X].RecType = qtMX then
Result:= TMXRecord(DNS.QueryResult[X]).ExchangeServer;
end;
finally
DNS.Free;
end;
end;
when try to resolve dns i am getting query refused by dns error error . am i wrong with that code can you please check ?
function Lookup(const Name: String): String;
var
X: Integer;
DNS: TIdDNSResolver;
begin
DNS:= TIdDNSResolver.Create(nil);
try
DNS.Host := 'mail.relativ.art';
DNS.WaitingTime := 5000;
DNS.QueryType:= [qtMX];
try DNS.Resolve(Name); except on E: Exception do begin writeln(E.Message); end; end;
for X:= 0 to DNS.QueryResult.Count-1 do begin
if DNS.QueryResult[X].RecType = qtMX then
Result:= TMXRecord(DNS.QueryResult[X]).ExchangeServer;
end;
finally
DNS.Free;
end;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
名称中包含
mail
的主机名(如mail.relativ.art
)可能不是 DNS 服务器。您需要将
Host
属性设置为实际的 DNS 服务器(最好是由您的 ISP 提供的服务器,或者像 Google 这样的公共服务器),然后将所需的目标名称传递给Resolve()< /代码>。
如果您尝试查询
mail.relativ.art
的 MX 记录,则该主机是要解析的目标主机,而不是要将查询发送到的 DNS 服务器,例如:A hostname with
mail
in its name, likemail.relativ.art
, is likely not a DNS server.You need to set the
Host
property to an actual DNS server (preferrably one provided by your ISP, or a public one like Google), and then pass the desired target name toResolve()
.If you are trying to query MX records for
mail.relativ.art
, then that is the target host to resolve, not the DNS server to send the query to, eg: