summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--notFinishedCode/SSHTunnelClass.py52
1 files changed, 22 insertions, 30 deletions
diff --git a/notFinishedCode/SSHTunnelClass.py b/notFinishedCode/SSHTunnelClass.py
index e71f2ee..825898b 100644
--- a/notFinishedCode/SSHTunnelClass.py
+++ b/notFinishedCode/SSHTunnelClass.py
@@ -12,43 +12,35 @@ class SSHTunneling:
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
- #result = subprocess.Popen(['ssh', '-f', '-g', '-A', '-X', '-N', '-L', command, uad, '&'], stdout = subprocess.PIPE, stderr = subprocess.STDOUT, stdin = subprocess.PIPE).communicate()[0]
- #result = subprocess.Popen(['ssh', '-f', '-g', '-A', '-X', '-N', '-L', command, uad])
-
-
-
-# result = subprocess.Popen(['ssh', '-f', '-L', command, uad, 'sleep', '40'])
-# stdout = subprocess.PIPE
-# stderr = subprocess.PIPE
-# output = result.communicate()
-# status = result.poll()
-
-
- return subprocess.Popen(['ssh', '-N', '-L', command, uad], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
-# stat = ssh_proc.poll()
-# while stat == None:
-# stat = ssh_proc.poll()
-# sleep(1)
-# print 'test'
-# print stat
-# print 'ovo je output', stdout
-# print 'stderr ', stderr
-# print 'ovo je status', status
- # while status == 0:
- # status = result.poll()
- # print 'test'
- #print output
-# def closeTunneling(self):
+ try:
+ self.__sshTunnel = subprocess.Popen(['ssh', '-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, 80, '132.230.4.202', 'rz-gsm-testing', 'r')
-y = x.startTunneling()
+print x.startTunneling()
print 'Tunnel started '
sleep(50)
-y.kill()
+print x.killTunneling()
print 'kill tunnel'
-#print y