[Twisted-Python] Telnet server example?

Eugene Coetzee projects at reedflute.com
Tue Aug 10 14:17:39 EDT 2004

Britt Green wrote:

>So I got my Echo server working...kind of. There were some issues with
>Putty in Telnet versus Raw Mode, but that's a posting for elsewhere.
>Anyways, rather than re-invent the wheel I'd like to take advantage of
>Twisted's Telnet classes. Unfortunately I've not been able to find any
>examples of a server that uses Twisted's Telnet. I've tried writing my
>own code but I've not had any luck getting it to work.
>Therefore...would anyone mind showing me a minimal example of a server
>that uses the Telnet library?
>Many thanks,
>Twisted-Python mailing list
>Twisted-Python at twistedmatrix.com
Excuse the mess:

from twisted.protocols.telnet import *
from twisted.application import service,internet
from twisted.internet import protocol,defer

class TelnetProtocol(Telnet):
def connectionMade(self):
print "TelnetProtocol.connectionMade"

def telnet_Password(self, paswd):
"""I accept a password as an argument, and check it with the
checkUserAndPass method. If the login is successful, I call
# checked = self.checkUserAndPass(self.username, paswd)
# return "Done"
#if not checked:
# return "Done"
return "Command"

def dataReceived(self,data):
print "TelnetProtocol.dataReceived"
print data

class TelnetFactory(protocol.ServerFactory):
protocol = TelnetProtocol
def __init__(self, **kwargs): self.users = kwargs
def getUser(self, user):
print "TelnetFactory.getUser"
print user
return defer.succeed(self.users.get(user, "No such user"))


factory = TelnetFactory()
internet.TCPServer(1021, factory).setServiceParent(

Do not trust this code - it will open a telnet session without any user 
authentication - you have to play around a little with the class as 
documented at :




More information about the Twisted-Python mailing list