python编写的adb 脚本 (二)查看系统状态
来源:互联网 发布:网站用户数据分析 编辑:程序博客网 时间:2024/05/17 02:41
import os import time import subprocessfrom 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 = 1adb_cmd = "adb devices " root_cmd = "adb root"global wifi_nameif 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 电脑 使用 grepdef 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是否连上外网等待
需要源码自己下载
源码
阅读全文
0 0
- python编写的adb 脚本 (二)查看系统状态
- python编写的adb 脚本 (一)监控系统网速
- Windows环境下python备份脚本编写(二)
- python 脚本编写vm系统操作
- python监控脚本的编写
- 编写脚本程序用于监测系统服务http的运行状态
- 查看脚本返回的状态值
- 数据库查看EZ状态的脚本
- 用IOT的思维来管理我们的查看我们重要业务的服务器健康状态-接受消息脚本编写!
- 查看pga状态脚本
- 如何使用adb 修改查看和修改gpio的状态
- Unity3D中角色的动画脚本的编写(二)
- 用IOT的思维来管理我们的查看我们重要业务的服务器健康状态-Powershell脚本编写-发送脚本解析!
- appium的python脚本编写前准备(三)
- 查看系统的所有port的状态
- 命令free查看系统的内存状态
- linux学习笔记二_查看系统使用状态
- Hibernate配置文件的编写二(实体类编写规则、状态、操作和OID生成策略)
- 自费出书多少钱?如何出书
- 解决虚拟机出错时,终端内核信息显示不全问题
- oracle11g 修改字符集 修改为ZHS16GBK
- RFID能否在工业制造领域铺开规模
- 几种常见的排序算法(插入排序,希尔排序,归并排序和快速排序),算法分析以及改进
- python编写的adb 脚本 (二)查看系统状态
- Java提高篇——Java 异常处理
- React native的flexbox布局(三)
- 用路由器创建自己的网页之ftp服务器
- 虚拟机不能联网的解决办法(从虚拟机创建到项目运行三)
- Method.invoke与MethodAccess.invoke的区别
- Oracle常用查询表空间的操作
- 超完整的Chrome浏览器客户端调试大全
- PHP中运算的先后顺序