当我在这里使用此代码引用: 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? 任何build议,将不胜感激:)
我发现了这个问题。
对于那些导致被调用地址的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); }