python脚本获取当前Android流量
2017-09-13 15:38
369 查看
import time #use to control time import subprocess import os from color import * ############################# #这里要进入自己adb目录。每个人根据自己的adb 目录设置 # 注意用的是反斜杠 ############################ adb_path='C:/Users/lvbiao/Desktop/adb' os.chdir(adb_path) Uid_cmd = 'adb shell "dumpsys package com.unisound.ant.platform.hardware | grep userId"' def getUid( ):#获取UID p1 = subprocess.Popen(Uid_cmd, shell=True, stdout=subprocess.PIPE); uidLongString = p1.stdout.read() uid_info = uidLongString.decode('UTF-8','strict') uidLongList = uid_info.split() uidMap = uidLongList[0] #print ("uidmap====" + uidMap ) uid= uidMap.split("=") #print("uid1===" + uid[1]) uid =uid[1] #print ("str is = " + uid ) return uid Rev_cmd = 'adb shell "cd proc && cd uid_stat && cd '+ getUid( ) +' && cat tcp_rcv"' def getRev():#获取某个APP的TCP下载流量 p_rev = subprocess.Popen(Rev_cmd, shell=True, stdout=subprocess.PIPE); flo_rec =int(p_rev.stdout.read()) #print ("flo_rec" + str(flo_rec)) clr.print_red_text("com.unisound.ant.platform.hardware recv Bytes ") clr.print_red_text("RECV BYTES is =" + str(flo_rec)) clr.print_red_text("========end===========") return flo_rec SEN_cmd = 'adb shell "cd proc && cd uid_stat && cd '+ getUid( ) +' && cat tcp_snd"' def getSEN():#获取某个APP的TCP下载流量 p_rev = subprocess.Popen(SEN_cmd, shell=True, stdout=subprocess.PIPE); flo_sen =int(p_rev.stdout.read()) #print ("flo_sen" + str(flo_sen)) clr.print_blue_text("========================") clr.print_blue_text("com.unisound.ant.platform.hardware SEND Bytes ") clr.print_blue_text("SEND BYTES is =" + str(flo_sen)) clr.print_blue_text("========end===========") return flo_sen clr = Color() while 1: getUid( ) time.sleep(1) getRev() time.sleep(1) getSEN() time.sleep(1)
实时监控系统收发的系统流量。监控的好工具
相关文章推荐
- Android获取当前系统正在运行应用及其数据流量
- python获取当前脚本下的所有方法
- Python获取运行目录与当前脚本目录的方法
- python脚本――获取系统当前时间与前一天的时间
- python获取android设备的GPS信息脚本分享
- 使用python编写脚本获取手机当前应用apk的信息
- Python脚本如何获取当前环节和用户等信息
- python脚本工具 - 4 获取系统当前时间
- python 获取当前当前目录 脚本目录 被执行脚本目录
- Python: 获取当前脚本目录、当前工作目录
- Cron 的在ubuntu 定时执行自己的程序&& Python获取当前 脚本文件的路径。
- Python 获取当前脚本文件路径目录
- python获取当前脚本路径(非常好用)
- python 脚本获取当前ip和网卡名字
- 获取Python脚本的当前行号
- python的subprocess:子程序调用(调用执行其他命令);获取子程序脚本当前路径问题
- python获取当前脚本文件路径
- 使用python编写脚本获取手机当前应用的信息
- Python获取当前脚本绝对路径
- 使用python编写脚本获取手机当前应用apk的信息