久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

JAVA獲得域名的IP地址

瀏覽:127日期: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
相關文章:
主站蜘蛛池模板: 弋阳县| 图木舒克市| 南溪县| 香港 | 襄垣县| 东光县| 宿州市| 华坪县| 辛集市| 盘锦市| 黔西| 修文县| 建阳市| 平度市| 永顺县| 工布江达县| 奉节县| 三亚市| 肥城市| 拉萨市| 温泉县| 宿州市| 永兴县| 汉沽区| 乌兰浩特市| 安吉县| 雷波县| 基隆市| 玛纳斯县| 邯郸县| 永仁县| 榆中县| 千阳县| 罗田县| 永昌县| 基隆市| 沁源县| 德江县| 中山市| 光泽县| 商都县|