Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ adbutils>=0.3.4,<0.4
tornado
requests
apkutils-patch>=0.5.4,<0.6
# uiautomator2==0.2.*
# uiautomator2==0.2.*
netifaces
24 changes: 23 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import socket
import string

import netifaces

def current_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand All @@ -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():
Expand Down