Jean-Paul Calderone wrote:
   sys.stdout.write('Password: ');
   #IAC DO ECHO     sys.stdout.write('\xFF\xFB\x01')
   password = raw_input()

If the client sends 'qwerty\r\n' everything is fine and the password get stored in the variable. But sometimes, depending on how broken the telnet client are, the client will send 'qwerty\r\000' instead and then my application will hang at 'password = raw_input()' forever.

Any suggestions?

It sounds like you might want to use a real implementation of the telnet
protocol in your application.  Such an implementation would deal with the
fact that telnet encodes \r as \r\0 for you.

Twisted includes a telnet implementation, as well as facilities for reading
stdin asynchronously (which will let you avoid indefinite hangs).
I am running this script inside a wrapper (honeyd), so i cant really use twisted since i don't have raw network access - i only got stdout, stdin and stderr to play with.

But i found a solution, posting it here for the archives:

password = ""
while 1:
  c = sys.stdin.read(1)
  if c == '\r' or c == '\n':
      break
  password = password + c



Regards,
jkv
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to