import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
/*
* InetAddress类
*/
public class Test01 {
public static void main(String[] args) throws UnknownHostException {
// 获取本机的InetAddress实例
InetAddress address = InetAddress.getLocalHost();
System.out.println("计算机名:" + address.getHostName());
System.out.println("IP地址;" + address.getHostAddress());
byte[] b = address.getAddress();
System.out.println("字节数组形式的IP:" + Arrays.toString(b));
System.out.println(address);
// 可以根据IP地址和计算机名获取InetAddress实例
InetAddress address2 = InetAddress.getByName("192.168.12.122");
InetAddress address1 = InetAddress.getByName("WIN-TEUR41V3M54");
}
}
InetAddress类
最新推荐文章于 2024-08-09 10:01:17 发布