[英]Getting the Host name of a Local IP address (java)
我在循环中使用此方法来获取本地网络中4个终端的主机名,该主机由ip地址terminal [i] .getIp()标识 。
try {
// Get hostname by textual representation of IP address
InetAddress addr = InetAddress.getByName(terminal[i].getIp());
// Get the host name
String hostname = addr.getHostName();
} catch (UnknownHostException e) {
}
这里的问题是代码要花很长时间才能返回结果(最多5秒),我想知道是否还有另一个更优化的方法。
尝试使用Google Guava的库,我认为还有更多优化的库
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/net/InetAddresses.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.