【发布时间】:2012-04-12 02:34:14
【问题描述】:
我在循环中使用此方法来获取本地网络中由 ip 地址 terminal[i].getIp() 标识的 4 个终端的主机名。
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 秒) 我想知道是否还有另一种更优化的方法。
【问题讨论】:
标签: java network-programming ip-address hostname