- A+
所属分类:Python
通过 curl -1(2,3) url 检测对应哪个ssl版本
V1
#custom HTTPS opener, banner's oracle 10g server supports SSLv3 only import httplib, ssl, urllib2, socket class HTTPSConnectionV3(httplib.HTTPSConnection): def __init__(self,*args,**kwargs): httplib.HTTPSConnection.__init__(self,*args,**kwargs) def connect(self): sock= socket.create_connection((self.host,self.port),self.timeout) if self._tunnel_host: self.sock= sock self._tunnel() try: self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1) except ssl.SSLError, e: print("Trying SSLv3.") self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1) class HTTPSHandlerV3(urllib2.HTTPSHandler): def https_open(self, req): return self.do_open(HTTPSConnectionV3, req) # install opener urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3())) if __name__== "__main__": r= urllib2.urlopen("https://www.t00ls.net") print(r.read())
V3
#custom HTTPS opener, banner's oracle 10g server supports SSLv3 only import httplib, ssl, urllib2, socket class HTTPSConnectionV3(httplib.HTTPSConnection): def __init__(self,*args,**kwargs): httplib.HTTPSConnection.__init__(self,*args,**kwargs) def connect(self): sock= socket.create_connection((self.host,self.port),self.timeout) if self._tunnel_host: self.sock= sock self._tunnel() try: self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_SSLv3) except ssl.SSLError, e: print("Trying SSLv3.") self.sock= ssl.wrap_socket(sock,self.key_file,self.cert_file, ssl_version=ssl.PROTOCOL_SSLv23) class HTTPSHandlerV3(urllib2.HTTPSHandler): def https_open(self, req): return self.do_open(HTTPSConnectionV3, req) # install opener urllib2.install_opener(urllib2.build_opener(HTTPSHandlerV3())) if __name__== "__main__": r= urllib2.urlopen("https://baidu.com") print(r.read())
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫