JAVA獲得域名IP地址的方法
更新時間:2015年06月18日 09:55:46 作者:瘋狂的流浪
這篇文章主要介紹了JAVA獲得域名IP地址的方法,涉及java域名操作的相關技巧,需要的朋友可以參考下
本文實例講述了JAVA獲得域名IP地址的方法。分享給大家供大家參考。具體如下:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class TestInetAddress {
InetAddress myIpAddress = null;
InetAddress[] myServer = null;
public static void main(String args[]) {
TestInetAddress address = new TestInetAddress();
System.out.println("Your host IP is: " + address.getLocalhostIP());
String domain = m.fzitv.net;
System.out.println("The server domain name is: " + domain);
InetAddress[] array = address.getServerIP(domain);
int count=0;
for(int i=1; i<array.length; i++){
System.out.println("ip "+ i +" "+ address.getServerIP(domain)[i-1]);
count++;
}
System.out.println("IP address total: "+count);
}
/**
* 獲得 localhost 的IP地址
* @return
*/
public InetAddress getLocalhostIP() {
try {
myIpAddress = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return (myIpAddress);
}
/**
* 獲得某域名的IP地址
* @param domain 域名
* @return
*/
public InetAddress[] getServerIP(String domain) {
try {
myServer = InetAddress.getAllByName(domain);
} catch (UnknownHostException e) {
e.printStackTrace();
}
return (myServer);
}
}
希望本文所述對大家的java程序設計有所幫助。
相關文章
SpringBoot的父級依賴:spring-boot-starter-parent詳解
SpringBoot通過父級依賴spring-boot-starter-parent實現項目快速構建,它依賴于spring-boot-dependencies來統(tǒng)一管理項目中的依賴版本,省去了手動指定版本信息的麻煩,這種機制不僅規(guī)定了默認的Java版本和編碼格式2024-09-09
java環(huán)境變量path和classpath的配置
這篇文章主要為大家詳細介紹了java系統(tǒng)環(huán)境變量path和classpath的配置過程,感興趣的小伙伴們可以參考一下2016-07-07
SpringBoot使用validation進行自參數校驗的方法
在SpringBoot項目中,利用validation依賴可以通過注解方式校驗數據庫交互參數,提高代碼可讀性和維護性,此方法避免了硬編碼校驗規(guī)則,方便后期規(guī)則變更,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧2024-09-09
Spring Cloud動態(tài)配置刷新RefreshScope使用示例詳解
這篇文章主要為大家介紹了Spring Cloud動態(tài)配置刷新RefreshScope使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08
SpringBoot使用Kafka來優(yōu)化接口請求的并發(fā)方式
這篇文章主要介紹了SpringBoot使用Kafka來優(yōu)化接口請求的并發(fā)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07

