summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/tricode/SSHTunnelBoxClass.py
diff options
context:
space:
mode:
authorgsmselftest2011-10-20 18:14:09 +0200
committergsmselftest2011-10-20 18:14:09 +0200
commit8c16ed8663a52c827ed562ea9bdbd7de02a48906 (patch)
tree538a807fe1bdb3bb8f0abf819750147ce4e98b5d /For Weekly Test/tricode/SSHTunnelBoxClass.py
parentMerge branch 'master' of lab.ks.uni-freiburg.de:lsfks/projekte/gsm-selftest (diff)
downloadgsm-selftest-8c16ed8663a52c827ed562ea9bdbd7de02a48906.tar.gz
gsm-selftest-8c16ed8663a52c827ed562ea9bdbd7de02a48906.tar.xz
gsm-selftest-8c16ed8663a52c827ed562ea9bdbd7de02a48906.zip
almost final version
Diffstat (limited to 'For Weekly Test/tricode/SSHTunnelBoxClass.py')
-rwxr-xr-xFor Weekly Test/tricode/SSHTunnelBoxClass.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/For Weekly Test/tricode/SSHTunnelBoxClass.py b/For Weekly Test/tricode/SSHTunnelBoxClass.py
new file mode 100755
index 0000000..0447365
--- /dev/null
+++ b/For Weekly Test/tricode/SSHTunnelBoxClass.py
@@ -0,0 +1,45 @@
+#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
+from time import sleep
+
+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.__sshTunnel = subprocess.Popen(['ssh','-N', '-L', command, uad], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ sleep(2)
+ 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
+
+