InetAddress类(获取主机ip与地址)

public class Address {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        InetAddress ip;
        try {
            ip = InetAddress.getLocalHost();
            String localname = ip.getHostName();
            String localip = ip.getHostAddress();
            System.out.println(localname);
            System.out.println(localip);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

}

 

posted @ 2019-04-04 10:53  小小超plus  阅读(2413)  评论(0编辑  收藏  举报