How to get All DNS records with iOS SDK

天涯浪子 提交于 2019-12-19 10:47:10

问题


i am looking for so long to get a solution regarding getting DNS records by using iOS SDK???

i am able to resolve ip addesses against host name here but that is not what i want... i need to get all DNS records including PTR, Name, NS, MX, CNAME etc.. please your help or a code snippet is very much appreciated


回答1:


Try exploring

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 */
    );

from

#include <dns_util.h>

I have actually written my objective-c wrapper using this function for all kinds of DNS records..but i cant get time to publish it somewhere




回答2:


In case others come across this in their search and want to see more details:

I found it to be from #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);

This is for if you wanted the MX records for a domain. callBack is a C method

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...
}

The callback method is called once it finds a response, note that you can receive multiple callbacks. For example when checking the domain of my office email I received 7 call backs.



来源:https://stackoverflow.com/questions/5376973/how-to-get-all-dns-records-with-ios-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!