简体   繁体   English

DnsQuery无法在某些特定的FQDN上获得有效地址

[英]DnsQuery can't get valid address on some specific FQDN

When I using this code reference here: http://support.microsoft.com/kb/831226 当我在这里使用此代码引用时: http//support.microsoft.com/kb/831226

I can complier success, but when i use it doing some dns query, the return address is weird, for example: 176.20.31.0 (this shouldn't be a valid address) 我可以编译成功,但当我使用它做一些dns查询时,返回地址很奇怪,例如:176.20.31.0(这不应该是一个有效的地址)

Here is my output: 这是我的输出:

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

But actually the tw.media.blizzard.com should be: (I query it by nslookup) 但实际上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

My question is why dnsquery doesn't work on some FQDN? 我的问题是为什么dnsquery不适用于某些FQDN? Any suggestion would be appreciated :) 任何建议将不胜感激:)

I found the problem. 我发现了这个问题。

For those FQDN which leading to invlid address, the common thing are all of their DNS record type are "DNS_TYPE_CNAME", not DNS_TYPE_A. 对于那些导致invlid地址的FQDN,常见的是他们所有的DNS记录类型都是“DNS_TYPE_CNAME”,而不是DNS_TYPE_A。

So we need to parse the whole PDNS_RECORD to get DNS_TYPE_A information. 因此我们需要解析整个PDNS_RECORD以获取DNS_TYPE_A信息。


I'll post my change here: 我会在这里发布我的更改:

Original code from MS: 来自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);
    }

My change here: 我在这里的变化:

    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);
    }       
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;

Thanks a lot for sharing this but I would like to add this for further clarification; 非常感谢您分享这一点,但我想补充一点,以便进一步澄清;

  • Even if you call DNSQuery_A with DNS_TYPE_A as wType for some FQDN, it may still return you a record for wType as (0x5) DNS_TYPE_CNAME. 即使您使用DNS_TYPE_A将DNSQuery_A作为某个FQDN的wType调用,它仍然可以将wType的记录返回为(0x5)DNS_TYPE_CNAME。

  • In such cases you can find the actual host name by inspecting the actual CNAME part of the QueryResults and ofcourse call the DNSQuery_A() API for the new hostname again. 在这种情况下,您可以通过检查QueryResults的实际CNAME部分找到实际的主机名,然后再次为新主机名调用DNSQuery_A()API。 Check the above Code snipette 检查上面的代码snipette

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM