I am trying to convert ip addresses to hostnames. I tried the answer given here . While the linux command "host" works for all the ip addresess I have, this code only works for some of them. Why would this be?
InetAddress addr = InetAddress.getByName("192.168.190.62");
String host = addr.getHostName();
System.out.println(host);
when looking at http://download.java.net/jdk7/archive/b123/docs/api/index.html?java/net/InetAddress.html you find...
Gets the host name for this IP address.
If this InetAddress was created with a host name, this host name will be remembered and returned ; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service . If a lookup of the name service is required, call getCanonicalHostName()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.