簡體   English   中英

獲取本地IP地址的主機名(java)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM