在安卓上获取DHCP的域名



我想获得 domain/search的值,该值可以在 Android 上的 MacOS 和 Linux /etc/resolv.conf中找到。

以下是MacOS和Linux(Fedora 25(上的示例:

苹果操作系统:

#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
domain home
nameserver 195.121.1.34
nameserver 195.121.1.66

Linux:

# Generated by NetworkManager
search home
nameserver 195.121.1.34
nameserver 195.121.1.66

如您所见,我在上述情况下寻找的值是 home .知道我如何在安卓上获得它吗?

我想做什么?

我正在尝试制作一个 Android 应用程序,该应用程序根据网络的设置,行为会有所不同。例如,它尝试查找服务foo.home(请注意,home是动态的,取决于网络(,如果成功,它将使用该服务器。否则,它将查询公共服务以找出它应该使用的服务器。

搜索路径的要点是它会自动应用于查询,因此应用程序不需要将其显式添加到域中。

我不确定您尝试使用哪种语言,因为您在这里针对不同的平台,但仅举个例子:

// start with the unqualified name
service = "foo";
try {
    InetAddress.getByName(addr);
} catch (UnknownHostException e) {
    // if `foo' did not resolve, use the external service
    // specified by the fully qualified name
    service = "public.whatever.com"
}

最新更新