How to Add SNI (server_hostname) Using sockets and ssl Modules in Python?

0

How to Add SNI (server_hostname) Using Sockets and ssl Modules in Python?

import socket, threading, select, ssl

def conecta(c, a):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('123.456.789.123', 444))



    connected = True
    while connected == True:
        r, w, x = select.select([c,s], [], [c,s], 3)
        if x: connected = False; break
        for i in r:
            try:
                # Break if not data.
                data = i.recv(8192)
                if not data: connected = False; break
                if i is s:
                    # Download.
                    c.send(data)
                else:
                    # Upload.
                    s.send(data)
            except:
                connected = False
                break
    c.close()
    s.close()


# Listen
l = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
l.bind(('', int(8080)))
l.listen(0)
while True:
    c, a = l.accept()
    threading.Thread(target=conecta, args=(c, a)).start()
l.close()
    
asked by anonymous 30.06.2018 / 20:14

0 answers