Java InetAddress.getByAddress()的使用

package test1;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 
 * @author TingFeng
 *
 */
public class Test1 {
		public static void main(String[] args) throws Exception{
			InetAddress local=InetAddress.getLocalHost();
			String ip="180.101.49.12";
			String[] ii=ip.split("\\.");
			byte[] ips=new byte[4];
			for(int i=0;i<4;i++){
				ips[i]=(byte)(Integer.parseInt(ii[i]));
			}
			InetAddress remote=InetAddress.getByAddress(ips);
			System.out.println(""+local.getHostAddress());
			System.out.println(""+local.getHostName());
			
			System.out.println(""+remote.getHostAddress());
			System.out.println(""+remote.getHostName());
			
		}
}

posted @ 2019-08-11 10:53  超级小白龙  阅读(1157)  评论(0)    收藏  举报