java 网络编程(一)InetAddress
package cn.sasa.net; import java.net.InetAddress; import java.net.UnknownHostException; public class InetAddressDemo { public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost();//主机名+IP String hostName = address.getHostName();//主机名 String hostAddress = address.getHostAddress();//IP InetAddress addr = InetAddress.getByName("www.163.com"); InetAddress addr1 = InetAddress.getByName("192.168.0.211"); System.out.println(address); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }