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??
NSLookup for iPhone and iPad allows you to see the public DNS records of domains or sub domains. Then you may also query the NS and CNAME records. It's also possible to force it to get an authoritative response from main DNS server of the domain.
Name Server lookup Access your command prompt. Use the command nslookup (this stands for Name Server Lookup) followed by the domain name or IP address you want to trace. Press enter. This command will simply query the Name Service for information about the specified IP address or domain name.
You can configure DNS Settings settings for users of an iPhone, iPad, Shared iPad, or Mac enrolled in a mobile device management (MDM) solution. Use the DNS Settings payload to specify apps that must use specific DNS settings.
On an Apple iPhone or iPad, you can view or change your DNS settings through iOS. Open the "Settings" app and tap "Wi-Fi." Find the network you want to configure and tap the "i" icon next to it. Tap "Configure DNS" to see and edit your DNS settings.
Figured out a change in this snippet makes it working
if (result == TRUE) {
NSMutableArray *tempDNS = [[NSMutableArray alloc] init];
for(int i = 0; i < CFArrayGetCount(addresses); i++){
struct sockaddr_in* remoteAddr;
CFDataRef saData = (CFDataRef)CFArrayGetValueAtIndex(addresses, i);
remoteAddr = (struct sockaddr_in*)CFDataGetBytePtr(saData);
if(remoteAddr != NULL){
// Extract the ip address
//const char *strIP41 = inet_ntoa(remoteAddr->sin_addr);
NSString *strDNS =[NSString stringWithCString:inet_ntoa(remoteAddr->sin_addr) encoding:NSASCIIStringEncoding];
NSLog(@"RESOLVED %d:<%@>", i, strDNS);
[tempDNS addObject:strDNS];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With