Python Telnet formatting?

  • Thread starter mentaltruckdriver
  • Start date
M

mentaltruckdriver

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".)

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 help is appreciated, I know I'm probably asking too many questions
already :)

Thanks everyone.
 
G

Gabriel Genellina

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
http://www.rfc-archive.org/getrfc.php?rfc=854 and RFC 855.
 
G

Gabriel Genellina

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
http://www.rfc-archive.org/getrfc.php?rfc=854 and RFC 855.
 
B

Bjoern Schliessmann

Gabriel said:
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.

With Twisted you don't need Telnetlib, twisted.conch.telnet does the
job. I would definitely look at twisted.words, too.

Regards,


Björn
 
G

Grant Edwards

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.

And we told you that you needed to implement the telnet protocol.
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".)

That "stuff" that you call "formatting" are commands for the
telnet protocol. Apparently you've ignored what I told you
about implementing the telnet protocol (or using something that
does).
How would I go about filtering this stuff out of the strings?

Once again: If you're trying to write a telnet server, you
need to implement the telnet protocol.
The thing is too, if I use other Telnet programs like
Microsoft Telnet, they don't have this formatting,

Different telnet clients act a little differently. Some won't
try to negotiate with the tenlet server until the server starts
the negotiation.
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.

You have to handle the telnet protocol if you want to talk to
telnet clients.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top