1、ping-ip
//创建连接 验证ip端口 public static boolean isReachableIp(String ipAddress) { try { InetAddress inetAddress = InetAddress.getByName(ipAddress); if (inetAddress.isReachable(5000)) { return true; } else { return false; } } catch (IOException e) { return false; } }
2、telnet-端口
//创建连接 验证ip端口端口 public static boolean isReachable(String ipAddress, int port) { try { Socket socket = new Socket(ipAddress, port); socket.close(); return true; } catch (IOException e) { return false; } }