无法在android中使用InetAddress获取主机名(计算机名称)

时间:2016-09-06 07:06:39

标签: android ip host hostname inetaddress

我正在开发一个模块来扫描本地网络以及通过同一网络连接的其他设备的IP,Mac,主机名和其他详细信息。

我无法从android中的InetAddress类获取Host PC名称。请检查我的以下代码:

String IpAddr = "192.168.1.52";

try {
      InetAddress inet = InetAddress.getByName(IpAddr);

      String address = inet.getHostAddress();
      String hostname = inet.getHostName();
      String canonicalhostname = inet.getCanonicalHostName();

      Log.w("Host Ip: ", IpAddr);
      Log.w("Host Address: ", address);
      Log.w("Host Name: ", hostname);
      Log.w("Canonical Host Name: ", canonicalhostname);
} catch (UnknownHostException e) {
      e.printStackTrace();
}

输出是:

Host Ip: 192.168.1.52
Host Address: 192.168.1.52
Host Name: 192.168.1.52
Canonical Host Name : 192.168.1.52

我也试过google但没有得到exect输出。

它不提供主机名,而是始终返回IP地址。

我也在尝试寻找设备类型(计算机/移动/笔记本电脑/打印机等......)

请帮帮我们..

0 个答案:

没有答案