您现在的位置 :八百米考试网范文常识知识电脑知识学习电脑技巧JAVA获得域名的IP地址

JAVA获得域名的IP地址

日期:11-01 21:55:12|八百米考试网| http://www.babaimi.com |电脑技巧

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 = “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获得域名的IP地址不错,可以推荐给好友哦。
本文Tags:IP地址  JAVA   电脑技巧电脑技巧大全电脑知识学习 - 电脑技巧
联系我们 | 热门专题 | 建筑工程 | 会计财务 | 职业资格 | 医学考试 | 外语学历 | 下载中心 | 范文中心 | 作文大全 | 中小学教育


Copyright www.babaimi.com
共享资料考试资料共享公务员考试试题会计从业资格考试试题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17