@Override
    public boolean verify(X509Certificate[] certs, String host, SSLSession session) {
        if (certs.length > 0) {
            return verify(host, certs[0]);
        } else {
            try {
                Certificate[] certificates = session.getPeerCertificates();
                return verify(host, (X509Certificate) certificates[0]);
            } catch (SSLException e) {
                return false;
            }
        }
    }
Quick and dirty pattern to differentiate IP addresses from hostnames. This
is an approximation of Android's private InetAddress#isNumeric API.

<p>This matches IPv6 addresses as a hex string containing at least one
colon, and possibly including dots after the first colon. It matches IPv4
addresses as strings containing only decimal digits and dots. This pattern
matches strings like "a:.23" and "54" that are neither IP addresses nor
hostnames; they will be verified as IP addresses (which is a more strict
verification).
common/src/main/java/org/conscrypt/OkHostnameVerifier.java