本文主要是介绍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[] 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()); } }
这篇关于InetAddress的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!