示例#1
0
    def __init__(self):
        Class.__init__(self, None)

        self.log_dir = "%(HOME)s/logs" % os.environ
        self.log_thread = LogThread(directory=self.log_dir, prefix="forwarder", note="Forwarder", name="LogThread")
        self.log_thread.start()

        self.log_queue = self.log_thread.queue
        self.log = self._log # log method

        self.delay = 60 # seconds
        self.host = "10.0.0.222"
        self.port = 22  
        self.username = "******"
        self.password = "******"

        self.forwards = [
            {   "reverse" : False,
                "proxy"   : ("10.0.0.222", 22),
                "bind"    : ("127.0.0.1", 2222),
                "target"  : ("127.0.0.1", 22),
            },
            {   "reverse" : True,
                "proxy"   : ("10.0.0.222", 22),
                "bind"    : ("127.0.0.1", 2222),
                "target"  : ("127.0.0.1", 22),
            },
        ]
示例#2
0
class Forwarder(Class):
    def __init__(self):
        Class.__init__(self, None)

        self.log_dir = "%(HOME)s/logs" % os.environ
        self.log_thread = LogThread(directory=self.log_dir, prefix="forwarder", note="Forwarder", name="LogThread")
        self.log_thread.start()

        self.log_queue = self.log_thread.queue
        self.log = self._log # log method

        self.delay = 60 # seconds
        self.host = "10.0.0.222"
        self.port = 22  
        self.username = "******"
        self.password = "******"

        self.forwards = [
            {   "reverse" : False,
                "proxy"   : ("10.0.0.222", 22),
                "bind"    : ("127.0.0.1", 2222),
                "target"  : ("127.0.0.1", 22),
            },
            {   "reverse" : True,
                "proxy"   : ("10.0.0.222", 22),
                "bind"    : ("127.0.0.1", 2222),
                "target"  : ("127.0.0.1", 22),
            },
        ]

    def run(self):
        try:
            while 1:

#pxssh.pxssh()
#  .login(
#       address,
#       username,
#       password=,
#       original_prompt=,
#       login_timeout=,
#       port=,
#       quiet=,
#       sync_multiplier=,
#       check_local_ip=
#   )
#
                self.conn = pxssh.pxssh()
                self.log("Connectiong to %s:%d ..." % (self.host,self.port))
                self.conn.login(self.host, self.username, password=self.password, port=self.port)
                self.log("Connected.")

                self.conn.sendline("ls")
                self.conn.prompt()
                self.log("Proof:" + self.conn.before)

                self.log("Adding forwards:")
                self.log("  Testing, so nothing yet.")
                self.log("All forwards added.")

                self.log("Connected. Entering the keep-alive loop ...")
                while open:
                    time.sleep(self.delay)
                    self.conn.sendline()
                    if not self.conn.prompt(timeout=5.0):
                        self.log("Connection to %s:%d dropped. Will re-open" % (self.host,self.port))
                        self.conn.logout()
                        break
                    self.log("Connection is up.")

        except KeyboardInterrupt:
            pass

        self.log_thread.halt()