根据DNS获得IP

 

/**
 * 根据DNS获得IP
 * @author MichaelShi
 *
 */
public class GetIP {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		InetAddress myIP = null;
		
		
		try {
			//根据域名获得IP地址
			myIP = InetAddress.getByName("www.google.com.hk");
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("myIP:" + myIP);

	}

}
运行结果:myIP:www.google.com.hk/72.14.203.105

你可能感兴趣的:(Google)