如何使用python计算http和ssl版本

2024-10-01 17:36:35 发布

您现在位置:Python中文网/ 问答频道 /正文

python中有没有一种好方法可以检查网站/url是否支持http2以及它支持哪些SSL版本。在

我要找的是可以通过使用命令来实现的

openssl s_client ­connect domain:443 ­nextprotoneg ''

这个openssl命令的输出包含这样一行:Protocols advertised by server: h2, spdy/3.1, http/1.1,通过这行我可以了解http2的支持。在

^{pr2}$

上面命令输出中的这一行->TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256可以告诉我所使用的SSL版本。在

我不想运行这些命令并解析输出,因为我觉得应该有更好的方法来完成它。在


Tags: 方法命令版本clienturlssl网站domain
1条回答
网友
1楼 · 发布于 2024-10-01 17:36:35

您可以使用Hyper库。在

from hyper import HTTPConnection

conn = HTTPConnection('google.com:443')
# If request made over http/1.1 then result will be None
if conn.request('HEAD', '/') is not None:
    # Return a string identifying the protocol version used by the current SSL channel
    print(conn._sock._sck.version()) # little bit dirty, but work

相关问题 更多 >

    热门问题