首页 > Web开发 > 详细

网络(Internet)

时间:2020-02-12 15:56:32      阅读:64      评论:0      收藏:0      [点我收藏+]

(1)获取IP地址

技术分享图片
 1 package JavaEE.JavaBaseExampleTest.Internet;
 2 
 3 import java.net.InetAddress;
 4 import java.net.UnknownHostException;
 5 
 6 /**
 7  * 使用 InetAddress 类的 InetAddress.getByName() 方法来获取指定主机(网址)的IP地址
 8  */
 9 public class GetIP {
10     public static void main(String[] args){
11         InetAddress address = null;
12         try {
13             address = InetAddress.getByName("www.w3cschool.cn");
14         }catch (UnknownHostException e){
15             System.exit(2);
16         }
17         System.out.println(address.getHostName() + "=" + address.getHostAddress());
18         System.exit(0);
19     }
20 }
View Code

 

网络(Internet)

原文:https://www.cnblogs.com/skygrass0531/p/12299270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!