title: Python OpenSSL: openssl s_client -connect
body: <p>What is the equivalent to <code>sudo openssl s_client -connect</code> in python open ssl?</p>
  
  <p>I have looked over documentation and have yet to find anything that is useful. I want to compare the results to the certifier lib, because I am not sold that the certifier lib is actually accurate. I just want to get the following: </p>
  
  <pre><code>---
  New, TLSv1/SSLv3, Cipher is AES128-SHA
  Server public key is 2048 bit
  Secure Renegotiation IS supported
  Compression: NONE
  Expansion: NONE
  SSL-Session:
      Protocol  : TLSv1
      Cipher    : AES128-SHA
      Session-ID: CEB4CF30EA4F1074039F5596CDDCA1073D683FFAC6D1DA1F68FCBA0FDDADDD38
      Session-ID-ctx:
      Master-Key: F5929F0740A855C32F6755ED45710D467314AF16BE52962FC8664A6E5105A6004DEC9E64B92DFEFAC6FE80FDDE65C814
      Key-Arg   : None
      Start Time: 1490843868
      Timeout   : 300 (sec)
      Verify return code: 0 (ok)
  ---
  </code></pre>
  
  <p>That I would get in the command line call. </p>
  
  <p>Basically, I want an equivalent to the following:</p>
  
  <pre><code>cert = CertInfo(host=hostname, port=443)  # ('RC4-SHA', 'TLSv1/SSLv3', 128)
  info = cert.cipher()
  </code></pre>
  
  <p>I do not know any information what so ever about the host, other than the domain, so I am trying to figure out how to do a bare connection. This is apparently incorrect because it errors: </p>
  
  <pre><code>context = ssl.create_default_context()
  
  conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=hostname)
  conn.connect(('google.com', 443))
  
  cert = conn.getpeercert()
  </code></pre>