Python Telnet formatting?

Gabriel Genellina gagsl-py2 at
Sun Mar 2 11:08:01 CET 2008

En Sat, 01 Mar 2008 22:51:08 -0200, <mentaltruckdriver at> escribi�:

> Hi everyone:
> I posted here a couple days ago looking for some help creating a
> Telnet-based chat server. You guys pointed me to Twisted, which has
> solved most of my issues.
> However, what I want to do is analyze strings received for keywords
> such as 'listcmds' and have the server return something to the client.
> I know how to do that part, at least.
> The issue is, when I use clients like PuTTY, it returns a lot of what
> appears to be formatting (e.g. if I typed Hello, it would return "\xff
> \xfb\x1f\xff\
> xfb \xff\xfb\x18\xff\xfb'\xff\xfd\x01\xff\xfb\x03\xff\xfd\x03Hello".)

They are part of the telnet protocol; 0xFF (IAC=Interpret as Command)  
starts a two or three byte command sequence.
Weren't you using telnetlib? It's supposed to handle this transparently.

> How would I go about filtering this stuff out of the strings? The
> thing is too, if I use other Telnet programs like Microsoft Telnet,
> they don't have this formatting, so I want to be able to recognize if
> it does have this formatting and act based on if it does or if it
> doesn't.

Any client could send similar commands at the start of the session, or  
even later.

> Any help is appreciated, I know I'm probably asking too many questions
> already :)

It isn't too hard to filter them out, if you want to do it by hand. See  
the source for telnetlib, and the original Telnet specificacion, RFC 854 and RFC 855.

Gabriel Genellina

More information about the Python-list mailing list