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());
}
}
Java InetAddress.getByAddress()的使用
最新推荐文章于 2022-12-17 12:04:11 发布