summaryrefslogtreecommitdiffstats
path: root/Under-Testing/Server-Code-New/SSHTunnelBoxClass.py
diff options
context:
space:
mode:
authorgsmselftest2011-11-16 18:06:02 +0100
committergsmselftest2011-11-16 18:06:02 +0100
commit8a7755d6f96e599fe75ac8e5e1c6994138f4b99e (patch)
tree9b320feb695cfbadd605808b2db5795e240e9399 /Under-Testing/Server-Code-New/SSHTunnelBoxClass.py
parent delete dummy comment (diff)
downloadgsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.tar.gz
gsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.tar.xz
gsm-selftest-8a7755d6f96e599fe75ac8e5e1c6994138f4b99e.zip
under Testing folder
Diffstat (limited to 'Under-Testing/Server-Code-New/SSHTunnelBoxClass.py')
-rw-r--r--Under-Testing/Server-Code-New/SSHTunnelBoxClass.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Under-Testing/Server-Code-New/SSHTunnelBoxClass.py b/Under-Testing/Server-Code-New/SSHTunnelBoxClass.py
new file mode 100644
index 0000000..1b76d0b
--- /dev/null
+++ b/Under-Testing/Server-Code-New/SSHTunnelBoxClass.py
@@ -0,0 +1,44 @@
+#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)
+ sleep(2)
+ self.__tunnelStarted = 1
+ return 1
+ except Exception, e:
+ error = str(e)
+ return 0
+
+ def killTunneling(self):
+ if self.__tunnelStarted == 1:
+ try:
+ self.__sshTunnel.kill()
+ self.__tunnelStarted = 0
+ return 1
+
+ except Exception, e:
+ error = str(e)
+ return 0
+
+