How to perform DNS query on iOS

Posted by yasirmturk on Stack Overflow See other posts from Stack Overflow or by yasirmturk
Published on 2011-02-15T06:10:45Z Indexed on 2011/02/23 7:25 UTC
Read the original article Hit count: 165

Filed under:
|
|

i want to perform some DNS queries e.g. to get IP records against a specific domain name, i am looking for a preferred way or some useful snippet for this on iOS 3.2+ SDK. thanx in advance

part from other snippets i found this code

 Boolean result;
 CFHostRef hostRef;
 NSArray *addresses;
 NSString *hostname = @"apple.com";
 hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
 if (hostRef) {
      result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
      if (result == TRUE) {
           addresses = (NSArray*)CFHostGetAddressing(hostRef, &result);
      }
 }
 if (result == TRUE) {
      [addresses enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
             NSString *strDNS = [NSString stringWithUTF8String:inet_ntoa(*((struct in_addr *)obj))];
           NSLog(@"Resolved %d->%@", idx, strDNS);
      }];

 } else {
      NSLog(@"Not resolved");
 }

but this is producing same IP for every host Resolved 0->220.120.64.1 any help??

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ipad