前面提及的:OSI,TCP-IP,IP地址,端口,协议概念我都清楚,所以我直接跳过前面,来到使用这里。
//获取本机IP InetAddress ip = InetAddress.getLocalHost(); System.out.println(ip); //***/169.254.93.173 String sip = ip.getHostAddress(); String name = ip.getHostName(); System.out.println(name+" "+ sip); //获取其他主机信息 ip = InetAddress.getByName("www.baidu.com"); System.out.println(ip);