InetAddress

这个类表示Internet协议的地址
image.png

  1. public static void main(String[] args) throws Exception {
  2. InetAddress ip1=InetAddress.getLocalHost();//静态方法
  3. InetAddress ip2=InetAddress.getByName("www.baidu.com");
  4. System.out.println(ip1.getHostAddress());
  5. System.out.println(ip2.getHostName());
  6. System.out.println(ip1.getHostName());
  7. System.out.println(ip2.getHostAddress());
  8. System.out.println(ip2.isReachable(5000));
  9. }

image.png