導航:首頁 > 編程語言 > pythonssl編程

pythonssl編程

發布時間:2023-09-21 03:07:33

❶ 怎麼用python 來實現 SSL登錄FTP python中有ftplib模塊,但它是普通登錄,也有ssl模塊,怎麼來實現呢

從python 2.7開始ftplib模塊就有一個支持ftp ssl的類FTP_TLS了
具體可以看這里
http://docs.python.org/library/ftplib.html#ftplib.FTP_TLS

❷ 如何驗證在Python SSL證書

importos
importglob
fromOpenSSL.SSLimportContext,TLSv1_METHOD,VERIFY_PEER,VERIFY_FAIL_IF_NO_PEER_CERT,OP_NO_SSLv2
fromOpenSSL.cryptoimportload_certificate,FILETYPE_PEM
fromtwisted.python.urlpathimportURLPath
fromtwisted.internet.sslimportContextFactory
fromtwisted.internetimportreactor
fromtwisted.web.clientimportgetPage
certificateAuthorityMap={}
forcertFileNameinglob.glob("/etc/ssl/certs/*.pem"):
#,solet'smakesureit'sreal.
ifos.path.exists(certFileName):
data=open(certFileName).read()
x509=load_certificate(FILETYPE_PEM,data)
digest=x509.digest('sha1')
#Now,de-.
certificateAuthorityMap[digest]=x509
(ContextFactory):
def__init__(self,hostname):
self.hostname=hostname
isClient=True
defgetContext(self):
ctx=Context(TLSv1_METHOD)
store=ctx.get_cert_store()
.values():
store.add_cert(value)
ctx.set_verify(VERIFY_PEER|VERIFY_FAIL_IF_NO_PEER_CERT,self.verifyHostname)
ctx.set_options(OP_NO_SSLv2)
returnctx
defverifyHostname(self,connection,x509,errno,depth,preverifyOK):
ifpreverifyOK:
ifself.hostname!=x509.get_subject().commonName:
returnFalse
returnpreverifyOK
defsecureGet(url):
returngetPage(url,HTTPSVerifyingContextFactory(URLPath.fromString(url).netloc))
defdone(result):
print'Done!',len(result)
secureGet("https://google.com/").addCallback(done)
reactor.run()

這個驗證要安裝Twisted 庫。

當然這樣的庫好多,如:pycurl,requests,M2Crypto

importrequests
requests.get('https://somesite.com',cert='/path/server.crt',verify=True)

❸ python3 代碼怎樣關閉url與ssl屬性校驗

importurllib.request
importssl

url="httpsurl"
header=headers={
"User-Agent":"Mozilla/5.0(Macintosh;IntelMacOSX10_7_0)AppleWebKit/535.11(KHTML,likeGecko)Chrome/17.0.963.56Safari/535.11"
}

request=urllib.request.Request(url,headers=header)
context=ssl._create_unverified_context()#忽略ssl證書驗證
res=urllib.request.urlopen(request,context=context)
print(res.read().decode("utf8"))

閱讀全文

與pythonssl編程相關的資料

熱點內容
java定義整數 瀏覽:369
怎麼添加數據透視表命令 瀏覽:799
hk4100f與單片機連接 瀏覽:861
門禁鑰匙加密可以復制嗎 瀏覽:194
單片機ad采樣交流信號 瀏覽:161
龍門銑外圓編程 瀏覽:518
gal編程工具 瀏覽:401
浙大翁愷老師用的什麼編譯器 瀏覽:590
gs5發動機壓縮比 瀏覽:716
稅控盤插上顯示未檢測加密盤 瀏覽:305
怎麼潛移默化的命令一個人 瀏覽:115
解壓筆爛了怎麼補 瀏覽:683
db什麼文件夾 瀏覽:868
寶駿730熱車壓縮機不工作 瀏覽:505
伺服器崩潰怎麼登錄 瀏覽:899
怎麼看伺服器是多少c 瀏覽:670
趣智校園app怎麼使用 瀏覽:155
樂家達要下什麼app 瀏覽:346
矩陣因子分解模型演算法思想 瀏覽:447
java6位驗證碼 瀏覽:765