DnsQuery无法获取某些特定FQDN的有效地址。

3

当我使用这段代码时,参考链接在此: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上无法工作? 任何建议都将不胜感激 :)


嗨,Luke,我使用的代码来自微软:http://support.microsoft.com/kb/831226/en这是你想要的吗?还是你只是指出微软提供的代码存在问题? - NCola.L
你确定IP地址真的是“错误”的吗?在针对该域名的连续nslookup命令之间清除DNS缓存会给我不同的结果,甚至是完全不同网络上的地址。这是Akamai,因此很可能涉及内容交付网络技术。 - Luke
Luke,谢谢你指出。我会尝试并将我的发现发布回来。 - NCola.L
2个回答

2

我找到了问题所在。

对于那些导致无效地址的FQDN,它们的共同点是所有DNS记录类型都是"DNS_TYPE_CNAME",而不是"DNS_TYPE_A"。

因此,我们需要解析整个PDNS_RECORD以获取DNS_TYPE_A信息。


我会在这里发布我的更改:
来自微软的原始代码:
    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);
    }       

0
PDNS_RECORD pQueryResults;

DNS_STATUS dResult = DnsQuery_A(
        "www.facebook.com",
        DNS_TYPE_A,
        DNS_QUERY_WIRE_ONLY, 
        NULL,
        (PDNS_RECORD*)&pQueryResults,
        NULL
    );

char* szActualHost = (char*) pQueryResults->Data.CNAME.pNameHost;

非常感谢您的分享,但我想进一步澄清一下:
  • 即使您使用DNS_TYPE_A作为wType调用DNSQuery_A来查询某个FQDN,它仍可能返回wType为(0x5) DNS_TYPE_CNAME的记录。

  • 在这种情况下,您可以通过检查QueryResults的实际CNAME部分找到实际的主机名,并当然再次为新主机名调用DNSQuery_A() API。请参阅上面的代码片段。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接