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

📄 ipversion.java

📁 精通Java核心技术源代码
💻 JAVA
字号:
// ==================== Program Discription ==================
// 程序名称:示例12-1: IPVersion.java
// 程序目的:查询ip的版本,熟悉InetAddress用法。
// ======================================================
import java.net.*;
import java.io.*;

public class IPVersion 
{
	   public static void main(String args[])
	   {
		 try
		 {
			InetAddress inetadd=InetAddress.getLocalHost();
			byte[ ] address=inetadd.getAddress( );
			if (address.length==4)
			{
            System.out.println(" the ip version is ipv4");
			  int firstbyte=address[0];
			  if((firstbyte&0x80)==0 )
			  System.out.println("the ip class is A");
			  else if ((firstbyte&0xC0)==0 )
			  System.out.println("the ip class is B");
			  else if((firstbyte&0xE0)==0 )
			    System.out.println("the ip class is C");
               else if((firstbyte&0xF0)==0 )
                   System.out.println("the ip class is D");
                   else if((firstbyte&0xF8)==0 )
                      System.out.println("the ip class is E");		   
			}
			else if(address.length==16)
			System.out.println("the ip version is ipv6");
	     }
	     catch (Exception e)
	     { };
	   }
}

⌨️ 快捷键说明

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