从iphone设置中获取DNS服务器IP [英] Get DNS server IP from iphone settings
本文介绍了从iphone设置中获取DNS服务器IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到一种方法来获取我的 DNS 服务器 IP,它出现在设置->wi-fi->详细信息->DNS 下.我不知道苹果是否允许以编程方式获取此信息.
I try to find a way how to get my DNS server ip which appear under settings->wi-fi->details->DNS. I don't know if apple allow to get this info programmatically.
推荐答案
我在 OS X 上使用了这个并为我工作,(也链接到 ibresolv.dylib)
I used this on OS X and worked for me, (link to ibresolv.dylib as well)
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <resolv.h>
#include <dns.h>
- (NSString *) getDNSAddressesStr
{
NSMutableString *addressStr = [[NSMutableString alloc]initWithString:@"DNS Addresses
"];
res_state res = malloc(sizeof(struct __res_state));
int result = res_ninit(res);
if ( result == 0 )
{
for ( int i = 0; i < res->nscount; i++ )
{
NSString *s = [NSString stringWithUTF8String : inet_ntoa(res->nsaddr_list[i].sin_addr)];
[addressStr appendFormat:@"%@
",s];
NSLog(@"%@",s);
}
}
else
[addressStr appendString:@" res_init result != 0"];
return addressStr;
}
}
这篇关于从iphone设置中获取DNS服务器IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文