InetAddress的使用

xiaoxiao2021-02-28  77

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[] bytes=address.getAddress(); System.out.println("字节数组形式的IP: "+ Arrays.toString(bytes)); System.out.println(address); //获取指定IP或者名称的inetAddress对象 InetAddress address2=InetAddress.getByName("115.196.153.44"); System.out.println("计算机名: "+address2.getHostName()); System.out.println("IP地址: "+address2.getHostAddress()); } }
转载请注明原文地址: https://www.6miu.com/read-47149.html

最新回复(0)