import os
import time
import subprocess
from color import *
#############################
#这里要进入自己adb目录。每个人根据自己的adb 和 Wireshark_path目录设置
# 注意用的是反斜杠
############################
adb_path='C:/Users/lvbiao/Desktop/adb'
Wireshark_path='D:/Wireshark'
os.chdir(adb_path)
tt = os.getcwd()
print ("tt===" + tt)
##################如果使用windows 这里就设为TRUE,MAC设为FALSE#########
Windows = True
######################################################################
flag = 1
adb_cmd = "adb devices "
root_cmd = "adb root"
global wifi_name
if Windows :
wifi_cmd = "adb shell wpa_cli -i wlan0 -p /data/misc/wifi/sockets list_networks"
#activity_cmd = "adb shell dumpsys activity | grep mFocusedActivity "
activity_cmd = 'adb shell "dumpsys activity | grep mFocusedActivity " '
ping_cmd = "adb shell ping -c 4 -W 1 120.92.137.92"
else:
wifi_cmd = "db shell wpa_cli -i wlan0 -p /data/misc/wifi/sockets list_networks"
activity_cmd = "adb shell dumpsys activity | grep mFocusedActivity "
ping_cmd = "adb shell ping -c 4 -W 1 120.92.137.92"
#linux 或 mac 电脑 使用 grep
def adb_root( ):
root_pipe = subprocess.Popen(root_cmd, shell=True, stdout=subprocess.PIPE).stdout;
root_info = root_pipe.read().decode();
global flag
flag = 0;
print (root_info);
def adb_connected_status( str):
fhandle = open('e:/aa.txt', "w");
fhandle.write(' 连上超级医生设备: ' + str[4]);
fhandle.write('\n')
print ('connected device ');
fhandle.close();
def adb_no_status():
fhandle = open('e:/aa.txt', "w");
print (' not connect device ');
fhandle.write('\n==========================\n');
fhandle.write(' 还没连上超级医生 ');
fhandle.write('\n==========================\n');
fhandle.close();
def get_activity( ):
fhandle = open('e:/aa.txt', "a");
activity_pipe = subprocess.Popen(activity_cmd, shell=True, stdout=subprocess.PIPE).stdout;
activity = activity_pipe.read();
activity_info = activity.decode('UTF-8','strict')
var_info = activity_info.split();
print ('正在显示的activity ==== ' + activity_info)
print ('var_info ==== ' + str(len(var_info)))
fhandle.write('===== ');
fhandle.write("正在显示的activity");
fhandle.write(' ======\n');
if len(var_info)==0:
fhandle.write("App还没启动完成")
else:
fhandle.write(var_info[3]);
fhandle.write('\n==========================\n');
fhandle.close();
def wifi_status( ):
fhandle = open('e:/aa.txt', "a");
wifi_pipe = subprocess.Popen(wifi_cmd, shell=True, stdout=subprocess.PIPE).stdout;
wifi_status = wifi_pipe.read();
wifi_info = wifi_status.decode('UTF-8','strict');
wifi_cur = wifi_info.split('\n')
for index in range(len(wifi_cur)):
print(wifi_cur[index])
if 'CURRENT' in wifi_cur[index]:
wifi_list_name = wifi_cur[index].split()
print('connected wifi is == ' + wifi_list_name[index] )
global wifi_name
wifi_name = wifi_list_name[1]
#print('wifi_name====' + wifi_name)
clr.print_red_text('====== configured wifi lists =========')
clr.print_red_text (wifi_info)
clr.print_red_text('====== end =========')
fhandle.write('==========已配置过 wifi lists==========\n');
fhandle.write(wifi_info);
fhandle.write('====================\n');
fhandle.close();
def wifi_connect():
net_no_connect = "unreachable"
net_pipe = subprocess.Popen(ping_cmd, shell=True, stdout=subprocess.PIPE).stdout;
net = net_pipe.read();
net_info = net.decode('UTF-8','strict')
if net_no_connect in net_info :
clr.print_red_text_with_blue_bg('====== 还没联通外网 =========')
clr.print_red_text_with_blue_bg('====== select wifi to connect =========')
clr.print_red_text_with_blue_bg (net_info)
clr.print_red_text_with_blue_bg('====== end =========')
else:
clr.print_green_text('==== wifi ok ====\n')
global wifi_name
clr.print_blue_text('connected wifi_name====' + wifi_name)
#print (net_info)
clr.print_green_text('====== end =========')
def meminfo():
mem_cmd = "adb shell busybox free -m"
mem = subprocess.Popen(mem_cmd, shell=True, stdout=subprocess.PIPE).stdout;
meminfo = mem.read().decode('UTF-8','strict')
mem_sp = meminfo.split()
clr.print_red_text ("#######系统总内存使用情况 MB 单位#### \n")
clr.print_red_text(meminfo)
clr.print_red_text("#######")
def nandinfo():
nand_cmd = "adb shell df "
nand = subprocess.Popen(nand_cmd, shell=True, stdout=subprocess.PIPE).stdout;
nandinfo = nand.read().decode('UTF-8','strict')
nand_sp = nandinfo.split('\n')
clr.print_blue_text ("####### system分区和data分区 #### \n")
clr.print_blue_text (nand_sp[0])
clr.print_blue_text (nand_sp[5])
clr.print_blue_text (nand_sp[8])
clr.print_blue_text("#######")
while 1:
clr = Color()
adb_pipe = subprocess.Popen(adb_cmd, shell=True, stdout=subprocess.PIPE).stdout
adb = adb_pipe.read()
adb_status = adb.decode('UTF-8','strict').split()
#print (wifi_status)
print (len(adb_status))
print ('===== ')
if len(adb_status) <= 4:
adb_no_status();
time.sleep(5)
continue
else:
adb_connected_status(adb_status);
print('============\n')
#print('flag === ' + str(flag))
if flag == 1:
adb_root( );
get_activity();
print('============\n')
wifi_status( );
wifi_connect();
meminfo();
nandinfo()
time.sleep(5)
可以查看当前连接的wifi 、wifi状态 、nand 信息 ram信息
正在显示的activity 。系统wifi是否连上外网等待
需要源码自己下载
源码