按IP地址获取HostName

时间:2016-04-07 11:11:36

标签: android

我使用Android Studio在Android中制作简单的IP扫描仪。我已经成功检查了主人是活着还是死了。但现在我还需要获取特定IP地址的主机名。

我尝试了以下两种方法,但它们返回的是IP地址而不是主机名

InetAddress inetAddr;
    inetAddr = InetAddress.getByName(host.hostname);
    String hostname = inetAddr.getHostName();
    String canonicalHostname = inetAddr.getCanonicalHostName();

我还在一些论坛上阅读了编辑主机文件,但这不是我想要的。

请帮忙

由于

1 个答案:

答案 0 :(得分:1)

试试这个

InetAddress address = InetAddress.getByName("www.example.com"); 
System.out.println(address.getHostAddress()); 
System.out.println(address.getHostName());

我希望这可以帮助你.. :)

相关问题