Minimal example of using twisted.manhole (Since it took me so long to get it working...)
Written by
on
in
Snaking.
from twisted.internet import reactor
from twisted.manhole import telnet
def createShellServer( ):
print 'Creating shell server instance'
factory = telnet.ShellFactory()
port = reactor.listenTCP( 2000, factory)
factory.namespace['x'] = 'hello world'
factory.username = 'mike'
factory.password = 'which1ta'
print 'Listening on port 2000'
return port
if __name__ == "__main__":
reactor.callWhenRunning( createShellServer )
reactor.run()
Turns out "service" is entirely superfluous, it's just assigned to the variable "service" in the namespace that's created. It's likely good practice to provide a pointer to something service-like (in the general Twisted sense of the word), but it's not actually a functional requirement.
The script above creates a little telnet server on port 2000 with a Python prompt available to you once you log on. You can add whatever you want to the factory.namespace dictionary to make it available to the user. You'd obviously want to use a different username and password, of course ;) .
So far I've been a little underwhelmed with the provided interpreter client, but then I've had to use my sister's machine to do the connecting, and it's telnet client seems a little... confused. Seems there's no per-character return echo? Doesn't seem like that could really be the case, hoping it's a Windows-telnet problem that will go away when I get a chance to install telnet on my workstation.
Comments
Comments are closed.
Pingbacks
Pingbacks are closed.
gjkjg on 09/26/2009 12:47 a.m. #
Really? I see nothing here. "Take heart, gentle coder, now you have an example that is, in fact, complete:" is the last line before the TRACKBACKS section that I see.
Mike Fletcher on 09/26/2009 11:38 a.m. #
Yeah, lost in the blog migration (all "extended content" sections were lost). The original source is still available in the way-back machine:
http://web.archive.org/web/20050206102203/blog.vrplumber.com/349#more
HTH,
Mike
Victor on 07/23/2012 10:48 a.m. #
Nice example. The only thing is that
if _name_ == "_main_":
should probably be
if __name__ == "__main__":