Iphone 如何使用iOS SDK获取所有DNS记录
我一直在寻找一个关于使用iOS SDK获取DNS记录的解决方案 我能够解决ip地址对主机名,但这不是我想要的。。。我需要获取所有DNS记录,包括PTR、Name、NS、MX、CNAME等。。非常感谢您的帮助或代码片段尝试探索Iphone 如何使用iOS SDK获取所有DNS记录,iphone,ios,ipad,Iphone,Ios,Ipad,我一直在寻找一个关于使用iOS SDK获取DNS记录的解决方案 我能够解决ip地址对主机名,但这不是我想要的。。。我需要获取所有DNS记录,包括PTR、Name、NS、MX、CNAME等。。非常感谢您的帮助或代码片段尝试探索 DNSServiceErrorType DNSSD_API DNSServiceQueryRecord ( DNSServiceRef *sdRef, DNSServiceFlags
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 */
);
从
#包括
实际上,我已经为所有类型的DNS记录编写了objective-c包装程序。但我没有时间将其发布到某个地方,以防其他人在搜索中遇到此问题并希望查看更多详细信息: 我发现它来自
#include
这适用于您是否需要域的MX记录<代码>回调是一种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次回电 如果我可以问一下的话,您最终做了什么?在遇到一些问题后,我发现您确实应该使用DNSServiceQueryRecord和DNSServiceSetDispatchQueue。不要忘记添加超时标志(第二个参数)。
// domain is a NSString
DNSServiceRef sdRef;
DNSServiceQueryRecord(&sdRef, 0, 0, [domain UTF8String], kDNSServiceType_MX, kDNSServiceClass_IN, callBack, NULL);
DNSServiceProcessResult(sdRef);
DNSServiceRefDeallocate(sdRef);
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...
}