2011-03-21 259 views
1

我在尋找這麼久才能獲得有關使用iOS SDK獲取DNS記錄的解決方案?如何使用iOS SDK獲取所有DNS記錄

我能夠解決對主機名here IP addesses但是這不是我想要的。我需要把所有的DNS記錄,包括PTR名稱NSMXCNAME等..請你幫忙或代碼片段是非常讚賞

+1

如果我可以查詢,你最終做了什麼? – 2012-03-01 19:19:59

回答

2

嘗試探索

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的包裝時發佈它的地方

1

如果別人遇到這種他們搜索,並希望看到更多的細節:

我發現它是從#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