Objective-C 检测 DNS

发布于 2024-08-08 08:20:57 字数 106 浏览 1 评论 0原文

有谁知道如何从应用程序检测 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北音执念 2024-08-15 08:20:57

要获取主机名,您可以使用 libc API gethostname:

#import <unistd.h>

...

char hostname[HOST_NAME_MAX];
int err = gethostname(hostname, HOST_NAME_MAX);
if(!err)
    NSLog(@"My hostname is %s", hostname);

To get the host name you can use libc API, gethostname:

#import <unistd.h>

...

char hostname[HOST_NAME_MAX];
int err = gethostname(hostname, HOST_NAME_MAX);
if(!err)
    NSLog(@"My hostname is %s", hostname);
哆啦不做梦 2024-08-15 08:20:57

另一种可能更好的方法是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文