Python Forum

Full Version: Script Conversion 2.7 to 3 (sockets)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all,

I'm trying to convert a script written in python2.7 to python3.
The first hurdle is how byte strings are handled between the two, which I believe I've worked around.

#python3
s.send(packet.encode('utf-8'))
#python2.7
s.send(packet)
The next issue seems to be around the implementation of sockets.

for n in list(enc_protocols.keys()):
    packet = X224_CONNECTION_REQUEST % n
    #TODO: need to convert to bytes-like object here
    print(binascii.hexlify(n.encode('utf-8')))

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    #s.sendall(packet.encode('utf-8'))
    s.send(packet.encode('utf-8'))
    #s.send(packet)
    response = s.recv(1024)
    #response = s.recv(4096)

    if (response[3] == "\x0b"):
        enc_protocols["\x00"][1] = True
        break
    else:
        if (response[11] == "\x02"):
            enc_protocols[n][1] = True
        else:
            errors[response[15]] = True
    
    #print binascii.hexlify(response)
    
    s.close()
Specifically line 11 above:
response = s.recv(1024)
Throws the error "Traceback (most recent call last):
File "rdp_check_ciphers.py", line 81, in <module>
response = s.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer"

I'm just after some pointers as to what is likely the problem if anyone has experienced this sort of issue themselves.

The script I'm looking at is this one: https://labs.mwrinfosecurity.com/tools/r...r-checker/

Thanks in advance,

Pumpernickel
I might add, the code works with python2.7 against my Windows 7 VM. I just don't understand why moving the python3 gives me a ConnectionResetError.