⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netipaddressdemo1.java

📁 java程序设计语言源代码
💻 JAVA
字号:
//Example 1 of Chapter 9

import java.net.*;

public class NetIpAddressDemo1
{
	public static void main(String args[])
	{
		try{
			//给定IP地址获取主机名
			InetAddress address1 = InetAddress.getByName( "159.226.3.9" );
			System.out.println( address1.getHostName() );
			System.out.println( address1.getCanonicalHostName() );
			
			//给定域名构造InetAddress
			InetAddress address2[] = InetAddress.getAllByName( "www.apple.com" );
			for(int i = 0; i < address2.length; i++ )
			{
				System.out.println( address2[i] );
			}
			
			//获取本地机的名称与地址
			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 );
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -