ipaddressseek.java

来自「JAVA网络编程电子书及源码」· Java 代码 · 共 54 行

JAVA
54
字号
package net;

/**
 * 在这里插入类型说明。
 * 建立日期:(00-7-31 11:48:16)
 * @程序设计者:
 */
import java.net.*;
 public class IPAddressSeek {
/**
 * IPAddressSeek 构造子注释。
 */
public IPAddressSeek() {
	super();
}
/**
 * 在这里插入方法说明。
 * 建立日期:(00-7-31 11:50:40)
 * @param args java.lang.String[]
 */
public static void main(String[] args) {
	InetAddress hostAddress;
	byte[] integer_address;
	if (args.length==0) {
	    try{
		    hostAddress=InetAddress.getLocalHost();
		    integer_address=hostAddress.getAddress();
		    System.out.println("The domain name of localHost is :\n\t\t\t"+hostAddress.getHostName());
		    System.out.println("The  IP address of localHost in the form of standardDot is :\n\t\t\t"+
			    hostAddress.getHostAddress());
		    System.out.println("The  IP address of localHost in the form of 4_integer_byte is :\n\t\t\t"+
			    integer_address[0]+"\t"+integer_address[1]+"\t"+integer_address[2]+"\t"+integer_address[3]);
		    }catch(UnknownHostException e ) {e.printStackTrace();}
	}
	else {
		try{
		    hostAddress=InetAddress.getByName(args[0]);
		    integer_address=hostAddress.getAddress();
		    System.out.println("The domain name of givenHost is :\n\t\t\t"+hostAddress.getHostName());
		    System.out.println("The  IP address of givenHost is :\n\t\t\t"+hostAddress.getHostAddress());
		    System.out.println("The  IP address of localHost in the form of 4_integer_byte is :\n\t\t\t"+
			    integer_address[0]+"\t"+integer_address[1]+"\t"+integer_address[2]+"\t"+integer_address[3]);
		    }catch(UnknownHostException e ) {e.printStackTrace();}
	}
}
		    
		




		
}

⌨️ 快捷键说明

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