gpt4 book ai didi

c++ - DnsQuery 无法获取某些特定 FQDN 上的有效地址

转载 作者:可可西里 更新时间:2023-11-01 09:34:47 25 4
gpt4 key购买 nike

当我使用这段代码时此处引用:http://support.microsoft.com/kb/831226

我可以编译成功,但是当我用它做一些 dns 查询时,返回地址很奇怪,例如:176.20.31.0(这不应该是一个有效地址)

这是我的输出:

C:\dnsq\Debug>dnsq.exe -n tw.media.blizzard.com -t A -s 8.8.8.8
The IP address of the host tw.media.blizzard.com is 176.20.31.0

但实际上tw.media.blizzard.com应该是:(我是通过nslookup查询的)

# nslookup tw.media.blizzard.com 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
tw.media.blizzard.com canonical name = tw.media.blizzard.com.edgesuite.net.
tw.media.blizzard.com.edgesuite.net canonical name = a1479.g.akamai.net.
Name: a1479.g.akamai.net
Address: 23.14.93.167
Name: a1479.g.akamai.net
Address: 23.14.93.157

我的问题是为什么 dnsquery 在某些 FQDN 上不起作用?任何建议将不胜感激:)

最佳答案

我发现了问题。

对于那些导致无效地址的FQDN,常见的是他们的DNS记录类型都是“DNS_TYPE_CNAME”,而不是DNS_TYPE_A。

所以我们需要解析整个 PDNS_RECORD 来获取 DNS_TYPE_A 信息。


我会在这里发布我的更改:

来自 MS 的原始代码:

    if(wType == DNS_TYPE_A) {
//convert the Internet network address into a string
//in Internet standard dotted format.
ipaddr.S_un.S_addr = (pDnsRecord->Data.A.IpAddress);
printf("The IP address of the host %s is %s \n", pOwnerName,inet_ntoa(ipaddr));

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}

我的改变:

    if(wType == DNS_TYPE_A) {
//convert the Internet network address into a string
//in Internet standard dotted format.
PDNS_RECORD cursor;

for (cursor = pDnsRecord; cursor != NULL; cursor = cursor->pNext) {
if (cursor->wType == DNS_TYPE_A) {
ipaddr.S_un.S_addr = (cursor->Data.A.IpAddress);
printf("The IP address of the host %s is %s \n", pOwnerName,inet_ntoa(ipaddr));
}
}

// Free memory allocated for DNS records.
DnsRecordListFree(pDnsRecord, freetype);
}

关于c++ - DnsQuery 无法获取某些特定 FQDN 上的有效地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13837439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com