美文网首页
5.0.2.InetAddress类

5.0.2.InetAddress类

作者: RockyLuo_290f | 来源:发表于2019-01-19 01:40 被阅读0次

用于管理Ip的类,没有构造器
1.单例模式
2.根据静态的方法来返回该对象

    public static void main(String[] args){
        
        //gei ip address
        try {
            InetAddress ia = InetAddress.getLocalHost();
            //Get Ip
            String ip = ia.getHostAddress();
            System.out.println(ip);
            
            //Get hostname,
            String hostname = ia.getHostName();
            System.out.println(hostname);
            
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

相关文章

网友评论

      本文标题:5.0.2.InetAddress类

      本文链接:https://www.haomeiwen.com/subject/zxlbdqtx.html