不能做Android上的反向DNS查找 [英] Can't do reverse DNS lookup on Android

查看:138
本文介绍了不能做Android上的反向DNS查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须连接到WiFi网络,一个IP地址的Andr​​oid设备。我这样做的IP地址我在Linux计算机上查找NS并证实没有为该IP地址对应的主机名。

I have an Android device connected to Wifi network with an IP address. I did NS lookup on my linux computer of this IP address and verified that there is a corresponding hostname for that IP address.

我有一块的Java code,它在我的Windows PC上运行的做反向DNS查找精(返回一个主机名):

I have a piece of Java code, which when run on my Windows PC does reverse DNS lookup fine (returns a hostname):

        String dnSuffix;
        String ipAddress = "10.228.59.217";
   InetAddress inetAddr;
    try {
        //inetAddr = InetAddress.getLocalHost();
        inetAddr = InetAddress.getByName(ipAddress);
        //System.out.println("inetAddr = " + inetAddr);
        Log.v(LOG_TAG, "inetAddr = " + inetAddr);
        if (inetAddr != null) {
            dnSuffix = inetAddr.getHostName();
            //System.out.println("dnSuffix is " + dnSuffix);
            Log.v(LOG_TAG,"dnSuffix is " + dnSuffix); 
        }
    } catch (UnknownHostException e) {
        //System.out.println("Error getting DN suffix: " + e.getMessage());
        Log.v(LOG_TAG,"Error getting DN suffix: " + e.getMessage());
    }

dnSuffix是预期在Windows上的主机名。

dnSuffix is the hostname as expected on Windows.

但是,在Android上它,而不是返回一个主机名,这说明它失败的IP地址。

But on Android, it returns an IP address instead of a hostname, which indicates that it failed.

我有,我会觉得我需要为这个在我的应用程序的所有权限:

I have all the permissions that I would think I need for this in my app:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" ></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

我发现了这个文档:

I found this documentation:

getCanonicalHostName

getCanonicalHostName

公共字符串getCanonicalHostName()

public String getCanonicalHostName()

获取此IP地址的完全限定域名。尽力而为方法,这意味着我们可能无法返回取决于底层系统配置的FQDN。
如果有安全管理器,该方法首先通过调用主机的checkConnect方法和-1作为参数,以查看是否调用code被允许知道主机名此IP地址,即连接到主机。如果不允许操作,则返回IP地址的文本再presentation。

Gets the fully qualified domain name for this IP address. Best effort method, meaning we may not be able to return the FQDN depending on the underlying system configuration. If there is a security manager, this method first calls its checkConnect method with the hostname and -1 as its arguments to see if the calling code is allowed to know the hostname for this IP address, i.e., to connect to the host. If the operation is not allowed, it will return the textual representation of the IP address.

返回:

的完全合格的域名为这个IP地址,或者如果操作没有被安全检查允许的IP地址的文本重新presentation

the fully qualified domain name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.

由于:

1.4

另请参见:

SecurityManager.checkConnect(java.lang.String中,INT)

SecurityManager.checkConnect(java.lang.String, int)

我也发现有类似问题的人:
https://groups.google.com/forum/#!msg/android-security-discuss/nVUoTz_zQBI/ZL4tzSbHbqoJ

I also found someone having similar problem: https://groups.google.com/forum/#!msg/android-security-discuss/nVUoTz_zQBI/ZL4tzSbHbqoJ

但没有解决方案。

任何人都可以在所有提供任何帮助?

Can anyone provide any help at all?

推荐答案

我真的不知道它能够在所有工作,继2.3源(缩短)

I'm really not sure it can works at all, following 2.3 sources (shortened)

inetAddr = InetAddress.getByName(ipAddress);
getByName(numeric) -> getAllByName/Impl(numeric) -> lookupHostByName(numeric)
return bytesToInetAddresses(getaddrinfo(host), host)[0]

主机是数字字符串,然后将得到的对象上调用的gethostname()返回主机(IP)

host is the numeric string, then calling getHostName() on the resulting object will return host (the ip)

这篇关于不能做Android上的反向DNS查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆