- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我使用这段代码时此处引用: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/
当我使用这段代码时此处引用:http://support.microsoft.com/kb/831226 我可以编译成功,但是当我用它做一些 dns 查询时,返回地址很奇怪,例如:176.20.31.
我需要将主机名转换为 IPv4 地址。例如,“google.com”到其 IPv4 地址 172.217.15.78。 正确的函数是什么? 最佳答案 由于您只需要解析主机名,因此请使用 getaddr
DnsQuery没有参数来指定要查询的服务器。另一方面,我见过 this sample ,它似乎在 MSDN 文档中标记为“保留且必须为 0”的参数中传递了一个 IP。 有没有什么方法可以查询特定的服
我是一名优秀的程序员,十分优秀!