Objective-C 检测 DNS
有谁知道如何从应用程序检测 iPhone 的 DNS?
更新:如果有不同的方法获取 DNS 服务器和 DNS 主机名,任何解决方案都是可以接受的。
Does anyone knows how can i detect from an app the DNS of the iPhone?
UPDATE: If there're different ways of obtaining the DNS server and DNS host name, any solution is acceptable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取主机名,您可以使用 libc API gethostname:
To get the host name you can use libc API, gethostname:
另一种可能更好的方法是使用 Core Foundations API。
更具体地说,
CFHost
API 将执行异步主机解析。您可以要求
CFHost
实例开始解析主机并测试其可达性。该过程将在运行循环上发生,当解析完成时您将收到回调。它是阻塞
gethostname
调用的一个很好的替代方案。An alternative, and possibly better way, to do this, is to use the Core Foundations APIs.
More specifically, the
CFHost
API will do asynchronous host resolution.You can ask a
CFHost
instance to start resolving a host and test for its reachability. The process will happen on a runloop and you will get callbacks when the resolution has finished.It is a good alternative for the blocking
gethostname
call.