如何使用iOS SDK获取所有DNS记录
问题描述:
我在寻找这么久才能获得有关使用iOS SDK获取DNS记录的解决方案?如何使用iOS SDK获取所有DNS记录
我能够解决对主机名here IP addesses但是这不是我想要的。我需要把所有的DNS记录,包括PTR,名称,NS,MX,CNAME等..请你帮忙或代码片段是非常赞赏
答
尝试探索
DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
(
DNSServiceRef *sdRef,
DNSServiceFlags flags,
uint32_t interfaceIndex,
const char *fullname,
uint16_t rrtype,
uint16_t rrclass,
DNSServiceQueryRecordReply callBack,
void *context /* may be NULL */
);
从
#include <dns_util.h>
我一直在使用该功能适用于各种DNS的records..but我不能得到实际写入我的Objective-C的包装时发布它的地方
答
如果别人遇到这种他们搜索,并希望看到更多的细节:
我发现它是从#include <dns_sd.h>
// domain is a NSString
DNSServiceRef sdRef;
DNSServiceQueryRecord(&sdRef, 0, 0, [domain UTF8String], kDNSServiceType_MX, kDNSServiceClass_IN, callBack, NULL);
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);
这是因为如果你想要的MX RECO rds为域。 callBack
是一个C方法
static void callBack(
DNSServiceRef sdRef,
DNSServiceFlags theFlags,
uint32_t theInterfaceIndex,
DNSServiceErrorType theErrorCode,
const char* theName,
uint16_t theType,
uint16_t theClass,
uint16_t theDataLength,
const void* theData,
uint32_t theTTL,
void* theContext)
{
// do your magic here...
}
回调方法被调用一次发现的响应,请注意,您可以接收多个回调。例如,当我检查我的办公室电子邮件的域名时,我收到了7个回叫。
+0
有一些问题后,我发现你真的应该使用DNSServiceQueryRecord和DNSServiceSetDispatchQueue。不要忘记添加超时标志(第二参数)。 – 2016-06-24 14:17:23
如果我可以查询,你最终做了什么? – 2012-03-01 19:19:59