国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

JAVA獲得域名的IP地址

瀏覽:109日期:2024-03-03 14:28:56

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 = "www.163.com";

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
相關文章:
主站蜘蛛池模板: 澳门| 上饶市| 米林县| 安塞县| 河源市| 佛坪县| 郸城县| 安化县| 涡阳县| 黔南| 枝江市| 麟游县| 寿宁县| 崇礼县| 昆山市| 荣昌县| 姚安县| 西乡县| 沙雅县| 曲水县| 东阿县| 咸丰县| 闽清县| 台南市| 湟中县| 英德市| 原平市| 土默特左旗| 乐亭县| 丽江市| 开原市| 察哈| 桐城市| 宁都县| 青河县| 阿图什市| 阿勒泰市| 历史| 天峻县| 靖远县| 大兴区|