Reputation: 133
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
Upvotes: 1
Views: 978
Reputation: 168786
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
Upvotes: 2