?? netipaddressdemo1.java
字號:
//Example 1 of Chapter 9
import java.net.*;
public class NetIpAddressDemo1
{
public static void main(String args[])
{
try{
//給定IP地址獲取主機(jī)名
InetAddress address1 = InetAddress.getByName( "159.226.3.9" );
System.out.println( address1.getHostName() );
System.out.println( address1.getCanonicalHostName() );
//給定域名構(gòu)造InetAddress
InetAddress address2[] = InetAddress.getAllByName( "www.apple.com" );
for(int i = 0; i < address2.length; i++ )
{
System.out.println( address2[i] );
}
//獲取本地機(jī)的名稱與地址
InetAddress address3 = InetAddress.getLocalHost();
System.out.println( address3 );
System.out.println( address3.getHostName() );
System.out.println( address3.getHostAddress() );
}
catch(UnknownHostException e)
{
System.err.println( e );
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -