-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellconnect.py
26 lines (23 loc) · 1.08 KB
/
shellconnect.py
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
import subprocess
import random
import time
from sys import argv
def connectToBluestacks():
connections = []
stdoutlineformatted = ""
item = subprocess.Popen(["shellconnect.bat"], shell=True, stdout=subprocess.PIPE) #launch subprocess to send commands to adb using .bat files
for stdoutline in item.stdout:
stdoutlineformatted += str(stdoutline, 'utf-8')
time.sleep(2)
##IF YOU SEND SHELLDEVICES IT RETURNS MULTIPLE LINES OF THE SAME PORT SO DISABLE IT SO IT DOESNT GET LOGGED TWICE
#item = subprocess.Popen(["shelldevices.bat"], shell=True, stdout=subprocess.PIPE) #launch subprocess to send commands to adb using .bat files
#for stdoutline in item.stdout:
# stdoutlineformatted += str(stdoutline, 'utf-8')
if stdoutlineformatted.find('localhost') == -1:
temp = ''
else:
temp = stdoutlineformatted[stdoutlineformatted.find('localhost') + 10:len(stdoutlineformatted)-1].split('localhost:') #grab only the ports
for x in range(0,len(temp)):
trim = temp[x]
connections.insert(x,int(trim[0:4]))
return connections