From ec18da7fbaa27a7bc5b6f844676931661ce89a35 Mon Sep 17 00:00:00 2001 From: xuweijia Date: Wed, 26 Jun 2019 10:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E8=AE=A1=E7=AE=97=E7=BD=91=E7=BB=9C=E5=8F=B7?= =?UTF-8?q?=20=E5=B9=B6=E5=9C=A8provider=E6=96=B0=E5=A2=9E=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=B1=9E=E6=80=A7remoteConnectAddressNetwork=EF=BC=8C?= =?UTF-8?q?=20=E8=BF=94=E5=9B=9E=E7=BB=99atxserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 注:requirement中新增一个包 --- device.py | 3 +++ requirements.txt | 3 ++- utils.py | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/device.py b/device.py index 7a2416f..d61928f 100644 --- a/device.py +++ b/device.py @@ -13,6 +13,7 @@ from device_names import device_names from freeport import freeport from utils import current_ip +from utils import current_ip_network STATUS_INIT = "init" @@ -33,6 +34,7 @@ def __init__(self, serial: str, callback=nop_callback): self._serial = serial self._procs = [] self._current_ip = current_ip() + self._current_ip_network = current_ip_network() self._device = adbclient.device(serial) self._callback = callback @@ -150,6 +152,7 @@ def port2addr(port): "atxAgentAddress": port2addr(self._atx_proxy_port), "remoteConnectAddress": port2addr(self._adb_remote_port), "whatsInputAddress": port2addr(self._whatsinput_port), + "remoteConnectAddressNetwork": self._current_ip_network } def adb_call(self, *args): diff --git a/requirements.txt b/requirements.txt index 352063a..a5e909a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ adbutils>=0.3.4,<0.4 tornado requests apkutils-patch>=0.5.4,<0.6 -# uiautomator2==0.2.* \ No newline at end of file +# uiautomator2==0.2.* +netifaces \ No newline at end of file diff --git a/utils.py b/utils.py index 3f1f759..081b1a5 100644 --- a/utils.py +++ b/utils.py @@ -6,7 +6,7 @@ import re import socket import string - +import netifaces def current_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -15,6 +15,28 @@ def current_ip(): s.close() return ip +def current_ip_network(): + def calc_network(netmask): + result = "" + for num in netmask.split('.'): + temp = str(bin(int(num)))[2:] + result += temp + return str(len([n for n in result if n != '0'])) + + machine_nick_name = netifaces.gateways()['default'][netifaces.AF_INET][1] + match_info = [netifaces.ifaddresses(interface)[netifaces.AF_INET] for interface in netifaces.interfaces() if interface == machine_nick_name] + ip = current_ip() + ip_and_network = ip + '/' + 'unknow' + # normally, if will match + if match_info: + try: + # addr = match_info[0][0]['addr'] + netmask = match_info[0][0]['netmask'] + net = calc_network(netmask) + ip_and_network = ip + '/' + net + except Exception as e: + pass + return ip_and_network def update_recursive(d: dict, u: dict) -> dict: for k, v in u.items():