[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Python Telnet formatting?

mentaltruckdriver

3/2/2008 12:51:00 AM

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\xffxfb \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.
4 Answers

Gabriel Genellina

3/2/2008 10:08:00 AM

0

En Sat, 01 Mar 2008 22:51:08 -0200, <mentaltruckdriver@gmail.com> 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
http://www.rfc-archive.org/getrfc.p... and RFC 855.

--
Gabriel Genellina

Gabriel Genellina

3/2/2008 10:08:00 AM

0

En Sat, 01 Mar 2008 22:51:08 -0200, <mentaltruckdriver@gmail.com> 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
http://www.rfc-archive.org/getrfc.p... and RFC 855.

--
Gabriel Genellina

Bjoern Schliessmann

3/2/2008 12:24:00 PM

0

Gabriel Genellina wrote:

> 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

--
BOFH excuse #329:

Server depressed, needs Prozac

Grant Edwards

3/2/2008 3:26:00 PM

0

On 2008-03-02, mentaltruckdriver@gmail.com <mentaltruckdriver@gmail.com> wrote:

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

--
Grant Edwards grante Yow! Yow! Those people
at look exactly like Donnie
visi.com and Marie Osmond!!