import socket
import ssl
import hashlib
import httplib
import OpenSSL
def main():
get_req="""GET / HTTP/1.1
Host: www.baidu.com
Connection: keep-alive
Accept: text/html
"""
try:
getsc=socket.socket(socket.AF_INET)
getsc.settimeout(15)
addr=socket.getaddrinfo('www.baidu.com',80)
getsc.connect((addr[0][4][0],80))
getsc.sendall(get_req)
totaldata=[]
#resp=getsc.recv(8192)
#print resp
while True:
outbuffer=getsc.recv(8192)
if not outbuffer:
break
totaldata.append(outbuffer)
print ''.join(totaldata)
except Exception as e:
print totaldata
finally:
getsc.close()
def test01():
certs=ssl.get_server_certificate(('www.baidu.com',443))
pkey=OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,certs)
#sha=hashlib.sha1()
#sha.update(certs)
dig=pkey.digest('sha1')
print dig
if __name__ == '__main__':
main()
python socket and SSL example
最新推荐文章于 2024-01-11 18:50:23 发布