java InetAddress基本使用

来源:互联网 发布:华为软件研发面试经验 编辑:程序博客网 时间:2024/05/17 22:07

java InetAddress基本使用

如下:
package com.xueyoucto.xueyou;import java.net.InetAddress;/** * Hello world! */public class App {    public static void main(String[] args) throws Exception{        System.out.println("hello world");        InetAddress ip = InetAddress.getByName("www.crazyit.org");        System.out.println("是否可达" + ip.isReachable(80));        System.out.println(ip.getHostAddress());        InetAddress local = InetAddress.getByAddress(new byte[]{127,0,0,1});        System.out.println("是否可达" + local.isReachable(5000));        System.out.println(local.getCanonicalHostName());    }}

运行结果:

0 0
原创粉丝点击