在 stf 平台的机器,启动一个服务来接受新设备的额链接,然后再启动一个该设备的 stf 服务
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: yinzhuoqun
@site: http://zhuoqun.info/
@email: yin@zhuoqun.info
@time: 2019/5/17 10:26
"""
import subprocess
from flask import Flask
from flask import request
from flask import Response
from flask import jsonify
app = Flask(__name__)
app.config["JSON_AS_ASCII"] = False
@app.route('/', methods=['post', 'get'])
def index():
if request.method in ['GET', ]:
print(request.args.to_dict())
return jsonify({"code": 200, "data": "OK", "msg": "请求成功"})
@app.route('/stf', methods=['post', 'get'])
def adb_start_post():
if request.method in ['POST', 'GET']:
ip = request.remote_addr
subprocess.Popen(
"stf provider --name shandianjideiMac.local --min-port 7400 --max-port 7700 "
"--connect-sub tcp://127.0.0.1:7114 --connect-push tcp://127.0.0.1:7116 "
"--group-timeout 900 --public-ip 192.168.3.153 --storage-url http://localhost:7100/ "
"--adb-host {ip} --adb-port 5037 --vnc-initial-size 600x800 "
"--mute-master never --allow-remote".format(ip=ip))
return jsonify({"code": 200, "data": {"ip": ip}, "msg": "请求成功"})
else:
return jsonify({"code": 405, "data": "", "msg": "Method Not Allowed"})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000, debug=False)
# app.run(debug=True)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: yinzhuoqun
@site: http://zhuoqun.info/
@email: yin@zhuoqun.info
@time: 2019/5/17 17:13
"""
import subprocess
import os
import time
try:
import requests
except Exception as e:
print("未安装 requests 模块, %s" % e)
os.system("pip install requests")
import requests
try:
os.system("adb kill-server")
subprocess.Popen("adb -a server nodaemon -P 5037")
except Exception as e:
print("ADB 执行出错,%s" % e)
else:
print("ADB 对外暴露端口(5037)成功")
try:
remote_host = "192.168.3.239"
post_url = "http://%s/stf" % remote_host
req = requests.post(post_url)
if req.status_code == 200 and req.json()["code"] == 200:
print("STF 远程服务(%s)启动成功" % remote_host)
else:
print("STF 远程服务(%s)启动失败 [%s]" % (remote_host, req.status_code))
except Exception as e:
print(e)
time.sleep(2)