private static boolean canConnect(String host, int port) {
    if (NetUtils.canConnectToRemoteSocket(host, port)) {
      return true;
    }
    else if ("localhost".equals(host)) {
      // `new Socket("localhost", port)` cannot connect to IPv6-only socket
      // without -Djava.net.preferIPv6Addresses=true
      // => try IPv6 localhost explicitly
      return NetUtils.canConnectToRemoteSocket("::1", port);
    }
    else {
      return false;
    }
  }
private static boolean canConnect(String host, int port)