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());
}
}
运行结果: