nyancat-server/nyancat.py

33 lines
820 B
Python
Raw Normal View History

2011-11-30 23:12:57 +00:00
#!/usr/bin/env python
import SocketServer
from subprocess import Popen, PIPE
from telnetsrvlib import TelnetHandler
2011-12-01 00:54:27 +00:00
class TNS(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
2011-11-30 23:12:57 +00:00
allow_reuse_address = True
class TNH(TelnetHandler):
def handle(self):
print self.TERM
p = Popen(["./nyancat"], shell=False, stdout=PIPE, stdin=PIPE, bufsize=0)
if (self.TERM.lower().find("xterm") != -1):
p.stdin.write("1\n")
elif (self.TERM.lower().find("linux") != -1):
p.stdin.write("3\n")
elif (self.TERM.lower().find("fallback") != -1):
p.stdin.write("4\n")
2011-12-01 00:54:27 +00:00
elif (self.TERM.lower().find("rxvt") == 0):
p.stdin.write("3\n")
2011-11-30 23:12:57 +00:00
else:
p.stdin.write("2\n")
while 1:
2011-11-30 23:26:22 +00:00
s = p.stdout.read(1024)
2011-11-30 23:12:57 +00:00
try:
self.write(s)
except:
p.kill()
return
tns = TNS(("0.0.0.0", 23), TNH)
tns.serve_forever()