有兩個子類
通過 InetAddress可以方便獲取一個域名下的IP
下面是例子
代碼
import java
import
public class TestInetAddress {
public static void main(String[] args) throws IOException {
test();
}
public static void test() throws IOException {
//獲取本機的IP地址
InetAddress address
System
System
System
//獲取
InetAddress address
System
System
System
//獲取我博客的IP地址
InetAddress address
System
System
//直接用ip地址構建
System
System
//獲取域名下所有的IP地址
// InetAddress[] address
InetAddress[] address
for (InetAddress address : address
// System
System
}
InetAddress address
System
}
}
運行輸出結果
lavasoft/
getHostAddress:
getHostName:
getHostAddress:
getHostName: lav
/
/
/
/
false
Process finished with exit code
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26639.html