code: public static boolean isAddressReachable(String hostname, int port) {
      try (Socket socket = new Socket(hostname, port)) {
        return true;
      } catch (IOException e) {
        return false;
      }
    }
docs: Validates whether a network address is reachable.
  
  @param hostname host name of the network address
  @param port port of the network address
  @return whether the network address is reachable