java常用类之——java.net.InetAddress

来源:互联网 发布:centos如何进入命令行 编辑:程序博客网 时间:2024/06/08 12:04
import java.net.InetAddress;public class demo{    public static void main(String[] args)throws Exception{        //以指定主机实例化        InetAddress Add = InetAddress.getByName("baidu.com");        //以本地主机实例化        Add = InetAddress.getLocalHost();        //以回环地址实例化        Add = InetAddress.getLoopbackAddress();        //取主机名        System.out.println(Add.getHostName());        //取主机地址        System.out.println(Add.getHostAddress());        //返回主机地址的数组形式        byte[] C_add = Add.getAddress();        for(int i=0;i<C_add.length;i++){        System.out.print("["+C_add[i]+"]");        }        //localhost        //127.0.0.1        //[127][0][0][1]    }}
原创粉丝点击