-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server_telnet.py
50 lines (42 loc) · 1.67 KB
/
Server_telnet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!python
__author__ = 'JacobAMason'
from twisted.internet.protocol import ServerFactory
from twisted.conch.telnet import StatefulTelnetProtocol
from twisted.internet import reactor
from time import sleep
class ShellTelnet():
def __init__(self):
pass
class TelnetServerProtocol(StatefulTelnetProtocol):
def connectionMade(self):
print "DEBUG: connectionMade called"
banner = [
" ____ ____ _ ",
" |_ \ / _|(_) ",
" | \/ | __ _ .--. .---. .--. _ _ __ .---. .---. _ .--. _ __ ",
" | |\ /| | [ |[ `.-. / /__\( (`\[ \ [ \ [ / /__\/ /__\[ '/'`\ [ \ [ ]",
" _| |_\/_| |_ | | | | | | \__.,`'.'.\ \/\ \/ /| \__.| \__.,| \__/ |\ '/ / ",
" |_____||_____[___[___||__'.__.[\__) )\__/\__/ '.__.''.__.'| ;.__[\_: / ",
" [__| \__.' "
]
for line in banner:
self.sendLine(line + "\r")
def lineReceived(self, line):
line = line.strip()
print "DEBUG: lineReceived called with %s" % line
if line != "exit":
self.sendLine("Echo: " + line + "\r")
else:
self.sendLine("Bye")
self.transport.loseConnection()
self.clearLineBuffer()
def connectionLost(self, reason):
print "DEBUG: connectionLost called with: %s" % str(reason)
def TelnetServerFactory():
factory = ServerFactory()
factory.protocol = TelnetServerProtocol
return factory
if __name__ == "__main__":
protocol = TelnetServerFactory()
reactor.listenTCP(23, protocol)
reactor.run()