summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/SSHTunnelClass.py
blob: e71f2eeed265878124ff9ffeaa0ec22a5fb6977e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import subprocess 
import string
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

	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):

x = SSHTunneling(50000, 80, '132.230.4.202', 'rz-gsm-testing', 'r')
y = x.startTunneling()
print 'Tunnel started '
sleep(50)
y.kill()
print 'kill tunnel'
#print y