1

Im using python3.3 version. I have Windows7 machine, I'm trying to write a program using socket module in python. I'm not to able get login prompt if I use socket module.

import socket
host = '10.155.208.33'
port= 23
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
data=s.recv(1024)
print(data)
>>> b"\xff\xfd%\xff\xfb\x01\xff\xfb\x03\xff\xfd'\xff\xfd\x1f\xff\xfd\x00\xff\xfb\x00"
s.sendall(b'\xff\xfe\x01\xff\xfd\x03\xff\xfc\x18\xff\xfc\x1f') >>> Im not sure whether this correct IAC client reply 
data =s.recv(1024)
print(data)
>>>b'' <<< server response is empty.

Im not familar with IAC commands. Can somebody point to correct handshake used for communicating between client and server?

I tried using telnetlib module for python3.3, module doesnt works properly on my windows machine.

Thanks, Anand

1
  • 1
    Have you read the RFCs? Commented Apr 8, 2015 at 8:23

1 Answer 1

2

You may safely respond negatively to each IAC negotiation request. That is, for each IAC-DO, reply IAC-WONT. For each IAC-WILL, reply IAC-DONT.

You may find this code helpful:

def read(s):
    while True:
        data = s.recv(10240)
        for do in re.findall('\xff\xfd.', data): # IAC DO cmd
            s.send('\xff\xfc'+do[2])  # IAC WONT cmd
        for will in re.findall('\xff\xfb.', data): # IAC WILL cmd
            s.send('\xff\xfe'+will[2])  # IAC DONT cmd
        data = re.sub('\xff[\xfb-\xfe].', '', data)
        if data != '':
            return data
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.