alen = len(sys.argv) if alen > 1: port = int(sys.argv[1]) if alen >= 4: PID = sys.argv[3] foundvirus = bool(sys.argv[2]) elif alen >= 3: foundvirus = bool(sys.argv[2]) else: foundvirus = False else: port = 10200 foundvirus = False server = socketserver.TCPServer((HOST, port), MyTCPHandler, bind_and_activate=False) server.allow_reuse_address = True server.foundvirus = foundvirus server.server_bind() server.server_activate() dummy_killer.setup_killer(server) dummy_killer.write_pid(PID) try: server.handle_request() except socket.error: print "Socket closed" server.server_close()
HOST = "localhost" alen = len(sys.argv) if alen > 1: port = int(sys.argv[1]) if alen >= 4: PID = sys.argv[3] foundvirus = bool(sys.argv[2]) elif alen >= 3: foundvirus = bool(sys.argv[2]) else: foundvirus = False else: port = 10200 foundvirus = False server = socketserver.TCPServer((HOST, port), MyTCPHandler, bind_and_activate=False) server.allow_reuse_address = True server.foundvirus = foundvirus server.server_bind() server.server_activate() dummy_killer.setup_killer(server) dummy_killer.write_pid(PID) try: server.handle_request() except socket.error: print "Socket closed" server.server_close()
connstream = ssl.wrap_socket(newsocket, server_side=True, certfile=self.certfile, keyfile=self.keyfile, ssl_version=self.ssl_version) return connstream, fromaddr def run(self): dummy_killer.write_pid(PID) try: self.serve_forever() except KeyboardInterrupt: print "Interrupt" except socket.error as e: print "Socket closed {}".format(e) def stop(self): self.keep_running = False self.server_close() class SSL_ThreadingTCPServer(SocketServer.ThreadingMixIn, SSL_TCP_Server): pass if __name__ == '__main__': server = SSL_ThreadingTCPServer((HOST_NAME, PORT), SSLTCPHandler, sys.argv[1], sys.argv[1]) dummy_killer.setup_killer(server, server.stop) server.run()
class ThreadingSimpleServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): def __init__(self): BaseHTTPServer.HTTPServer.__init__(self, (HOST_NAME, PORT), MyHandler) self.allow_reuse_address = True self.timeout = 1 def run(self): dummy_killer.write_pid(PID) try: while 1: sys.stdout.flush() server.handle_request() except KeyboardInterrupt: print "Interrupt" except socket.error: print "Socket closed" def stop(self): self.keep_running = False self.server_close() if __name__ == '__main__': server = ThreadingSimpleServer() dummy_killer.setup_killer(server, server.stop) server.run()