From b42ef6d7bc5b8974e0b88d96170be58a186b652b Mon Sep 17 00:00:00 2001 From: Refik Hadzialic Date: Sun, 11 Sep 2011 20:52:46 +0200 Subject: first working test website connected to the testing software! --- notFinishedCode/tricode/SSHTunnelClass.py | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 notFinishedCode/tricode/SSHTunnelClass.py (limited to 'notFinishedCode/tricode/SSHTunnelClass.py') diff --git a/notFinishedCode/tricode/SSHTunnelClass.py b/notFinishedCode/tricode/SSHTunnelClass.py new file mode 100755 index 0000000..12bedeb --- /dev/null +++ b/notFinishedCode/tricode/SSHTunnelClass.py @@ -0,0 +1,47 @@ +#Here is a tutorial how to generate and copy your RSA SSH public key :) +#>>> http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/ +import subprocess + +class SSHTunneling: + + def __init__(self, localPort, remotePort, remoteServer, username, password): + self.lPort = localPort + self.rPort = remotePort + self.rServer = remoteServer + + self.usern = username + self.passw = password + + self.__tunnelStarted = 0 + self.__sshTunnel = 1 + + def startTunneling(self): + if self.__tunnelStarted == 0: + command = str(self.lPort) + ':' + self.rServer + ':' + str(self.rPort) + uad = self.usern + '@' + self.rServer + + try: + self.__sshTunnel = subprocess.Popen(['ssh','-p','7884','-N', '-L', command, uad], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + self.__tunnelStarted = 1 + return 1 + except Exception, e: + print str(e) + return 0 + + def killTunneling(self): + if self.__tunnelStarted == 1: + try: + self.__sshTunnel.kill() + self.__tunnelStarted = 0 + return 1 + + except Exception, e: + print str(e) + return 0 + +x = SSHTunneling(50000, 50008, '10.4.58.241', 'lsfks', 'r') +print x.startTunneling() +print 'Tunnel started ' +sleep(50) +print x.killTunneling() +print 'kill tunnel' -- cgit v1.2.3-55-g7522