(1) to obtain an IP address
. 1 Package JavaEE.JavaBaseExampleTest.Internet; 2 . 3 Import the java.net.InetAddress; . 4 Import a java.net.UnknownHostException; . 5 . 6 / ** . 7 * using InetAddress.getByName InetAddress class () method to get the specified host (URL) of IP address . 8 * / . 9 public class Getip { 10 public static void main (String [] args) { . 11 InetAddress address = null ; 12 is the try { 13 is address = InetAddress.getByName ( "www.w3cschool.cn" ); 14 }catch (UnknownHostException e){ 15 System.exit(2); 16 } 17 System.out.println(address.getHostName() + "=" + address.getHostAddress()); 18 System.exit(0); 19 } 20 }