From 900194edee61b6dded593e04b435e9b7c9ca0517 Mon Sep 17 00:00:00 2001 From: Aaron Peschel Date: Wed, 30 Nov 2011 21:06:11 -0800 Subject: Made project more in line with Autotools standard. --- src/nyancat.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 src/nyancat.py (limited to 'src/nyancat.py') diff --git a/src/nyancat.py b/src/nyancat.py new file mode 100755 index 0000000..039581c --- /dev/null +++ b/src/nyancat.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +import SocketServer +import threading, os +from subprocess import Popen, PIPE +from telnetsrvlib import TelnetHandler + +class TNS(SocketServer.ThreadingMixIn, SocketServer.TCPServer): + 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") + elif (self.TERM.lower().find("rxvt") == 0): + p.stdin.write("3\n") + else: + p.stdin.write("2\n") + while 1: + s = p.stdout.read(1024) + try: + self.write(s) + except: + p.kill() + return + +class serverThread(threading.Thread): + def run(self): + tns = TNS(("0.0.0.0", 23), TNH) + tns.serve_forever() + +if __name__ == "__main__": + t = serverThread() + t.start() + raw_input("Let me know when to stop.") + os.kill(os.getpid(), 9) -- cgit v1.2.3