1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java域名获取ip_JAVA获得域名IP地址的方法

java域名获取ip_JAVA获得域名IP地址的方法

时间:2023-10-11 17:35:17

相关推荐

java域名获取ip_JAVA获得域名IP地址的方法

本文实例讲述了java获得域名ip地址的方法。分享给大家供大家参考。具体如下:

import .inetaddress;

import .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 = ;

system.out.println("the server domain name is: " + domain);

inetaddress[] array = address.getserverip(domain);

int count=0;

for(int i=1; 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程序设计有所帮助。

希望与广大网友互动??

点此进行留言吧!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。